프로그래머스 181919 콜라츠 수열 만들기

1 개요[ | ]

프로그래머스 181919 콜라츠 수열 만들기

2 C++[ | ]

#include <string>
#include <vector>

using namespace std;

vector<int> solution(int n) {
    vector<int> answer;
    while(true) {
        answer.push_back(n);
        if(n == 1) break;
        if(n%2==0) n /= 2;
        else n = 3*n+1;
    }
    return answer;
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}