문제
내가 작성한 정답
class Solution {
public int solution(int n, int t) {
return (int)Math.pow(2,t)*n;
}
}
Math.pow(밑, 지수)의 타입은 double이다.
다른 사람들이 작성한 정답
class Solution {
public int solution(int n, int t) {
int answer = 0;
answer = n << t; // n을 2의 t제곱으로 곱함
return answer;
}
}
class Solution {
public int solution(int n, int t) {
int answer = n;
for(int i=0; i<t; i++){
answer = answer+answer;
}
return answer;
}
}
class Solution {
public int solution(int n, int t) {
for(int i = 0; i < t; i++) {
n *= 2;
}
return n;
}
}
n << t : n을 2의 t제곱으로 곱함
Share article