- 내 풀이
class Solution {
public int solution(int n, int t) {
int answer = 0;
answer = n;
for (int i = 0; i < t; i++) {
answer = answer * 2;
}
return answer;
}
}
- 다른 사람 풀이
class Solution {
public int solution(int n, int t) {
int answer = 0;
answer = n << t;
return answer;
}
}
class Solution {
public int solution(int n, int t) {
int answer = 0;
answer = (int)Math.pow(2,t)*n;
return answer;
}
}
시프트 연산자 및 Math 함수 사용 예제다
이렇게 간단하게 끝나다니...
'프로그래머스 > [프로그래머스 - JAVA] Lv.0' 카테고리의 다른 글
[프로그래머스 - JAVA] 인덱스 바꾸기 (0) | 2023.03.10 |
---|---|
[프로그래머스 - JAVA] 최댓값 만들기(2) (0) | 2023.03.10 |
[프로그래머스 - JAVA] 직각삼각형 출력하기 (0) | 2023.03.10 |
[프로그래머스 - JAVA] 주사위의 개수 (0) | 2023.03.10 |
[프로그래머스 - JAVA] n의 배수 고르기 (0) | 2023.03.10 |
댓글