#include <string>
#include <vector>
using namespace std;
 
string solution(int n) 
{
    string answer = "";
    string num = to_string(n);
    char pattern[3= {'4''1''2'};
    int digit[100];
    int cnt = 0;
    
    for(int i = 0; n > 0; i++)
    {
        digit[i] = n % 3;
        n /= 3;
        cnt++;
        
        if(digit[i] == 0)
        {
            n--;
        }
        
        answer = pattern[digit[i]] + answer;
    }
    
    // for(int i = cnt-1; i >= 0; i--)
    // {
    //     answer += pattern[digit[i]];
    // }
 
    return answer;
}
cs

+ Recent posts