inblog logo
|
stupefyee
    알고리즘문제풀기

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

    프로그래머스 (120910)
    Stupefyee's avatar
    Stupefyee
    Jan 14, 2025
    [JAVA 문제 풀이] 62. 세균 증식
    Contents
    내가 작성한 코드다른 사람의 코드
    school.programmers.co.kr
    https://school.programmers.co.kr/learn/courses/30/lessons/120910
    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
    Contents
    내가 작성한 코드다른 사람의 코드

    stupefyee

    RSS·Powered by Inblog