[JAVA 문제 풀이] 62. 세균 증식

프로그래머스 (120910)
Stupefyee's avatar
Jan 14, 2025
[JAVA 문제 풀이] 62. 세균 증식
notion image

내가 작성한 코드

💡
class Solution { public int solution(int n, int t) { int answer = n; // 초기값 n으로 // t만큼 2곱하기 for(int i = 0; i < t; i++) { answer *= 2; } return answer; } }

다른 사람의 코드

💡
class Solution { public int solution(int n, int t) { int answer = 0; answer = n << t; return answer; } }
  • 비트 연산을 사용함
    • 비트연산으로 한칸씩 밀면 2를 곱한거랑 같은거니까 t만큼 밀어주기
Share article

stupefyee