본문 바로가기

IT/프로그래머스

[프로그래머스] 세균 증식 - Java

반응형

 

 

 

문제

 

 

 

 

 

 

풀이

문제 설명 그대로 1시간마다 2배씩 늘어나도록 루프를 돌린다.

 

 

 

코드

class Solution {
    public int solution(int n, int t) {
        int answer = n;
        for(int i=1; i<=t; i++){
            answer = answer*2;
        }
        return answer;
    }
}
반응형