
문제

내 풀이
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
// 2의 n제곱만큼의 방법이 있다.
Scanner sc = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
int num = sc.nextInt();
int answer = (int)Math.pow(2,num);
sb.append(answer);
System.out.println(sb.toString());
}
}
느낀점
문제가 주는 부담감에 비해 풀이가 아주 쉬웠다!
숏코딩으로 풀려면 미리 배열에 값을 넣어놓고 출력하면 될 것 같다.
번외 : 다른 풀이
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
// 2의 n제곱만큼의 방법이 있다.
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int [] answer = new int []{0, 2, 4, 8, 16, 32};
System.out.println(answer[num]);
}
}
아까는 200ms 나오고 이거는 204ms 나왔다 떼잉~ 아쉬워