본문 바로가기

코딩 테스트/프로그래머스

[Level 1, C++] 자연수 뒤집어 배열로 만들기

728x90
반응형

#include <string>
#include <vector>
using namespace std;

vector<int> solution(long long n) {
    vector<int> answer;
    string str = to_string(n);
    for(int i = str.length() - 1; i >= 0; i--) {
        answer.push_back(str.at(i) - 48);
    }
    return answer;
}
728x90
반응형