[프로그래머스/C++]Lv.0 - 세균 증식

YH J·2023년 4월 17일
0

프로그래머스

목록 보기
7/168

문제 링크

https://school.programmers.co.kr/learn/courses/30/lessons/120910

내 풀이

처음 세균의 수 n에 t번 만큼 2를 곱한다.

내 코드

#include <string>
#include <vector>

using namespace std;

int solution(int n, int t) {
    int answer = n;
    for (int i = 0; i < t; i++)
        answer *= 2;
    return answer;
}

다른 사람의 풀이

#include <string>
#include <vector>
using namespace std;
int solution(int n, int t) {
    return n << t;
}

다른 사람의 풀이 해석

쉬프트연산을 사용하였다.

profile
게임 개발자 지망생

0개의 댓글