
public int solution(int n, int t) {
int answer = n;
for(int i=1; i<=t; i++){
answer *= 2;
}
return answer;
}
public int solution(int n, int t) {
for(int i = 0; i < t; i++) {
n *= 2;
}
return n;
}
public int solution(int n, int t) {
return n << t;
}
<< 를 사용하여 문제를 풀 수 있다. a << b 는 a를 2의 b 제곱만큼 곱한 값 과 같다.세균이 1시간에 두 배씩 증식한다면, t 시간 후에는 n * 2^t 만큼의 세균이 있게 된다.
비트 연산을 사용해 이를 표현하면 n << t 와 같다.
이는 n을 t만큼 왼쪽으로 시프트하는 것과 동일하며, 결국 n * 2^t 를 계산하는 것과 같다.