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

    세균 증식

    난이도 최하
    화낼거양's avatar
    화낼거양
    Dec 04, 2024
    세균 증식
    Contents
    문제정답
     
    출처 : https://school.programmers.co.kr/learn/courses/30/lessons/120910
     
     

    문제

     
     
    notion image
     
    기본적으로 주어진 코드 :
    class Solution { public int solution(int n, int t) { int answer = 0; return answer; } }
     

    정답

     
    class Solution { public int solution(int n, int t) { int answer = n; for (int i = 0; i < t; i++) { answer *= 2; } return answer; } }
     
    • t 의 값이 1 증가할 때마다 반환값을 2배로 늘려야 합니다.
    • t 값이 1이라도 한번은 2배로 늘려야하기 때문에 반복문의 시작값은 0 입니다.
    Share article
    Contents
    문제정답

    moohyun

    RSS·Powered by Inblog