프로그래머스/[프로그래머스 - JAVA] Lv.0
[프로그래머스 - JAVA] 세균 증식
코딩하는 흰둥이
2023. 3. 10. 10:01

- 내 풀이
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 함수 사용 예제다
이렇게 간단하게 끝나다니...