function solution(n) {
var answer = 0;
let threes=3;
let how=1;
const NtoThree=[]
const reverseThree=[];
let remain=n;
if(n===1)
threes=1
while(threes*3<=n){
threes*=3;
how+=1;
}
for(let i=0;i<how+1;i++){
NtoThree.push(Math.floor(remain/threes));
remain%=threes;
threes/=3;
}
while(NtoThree.length>0)
reverseThree.push(NtoThree.pop());
console.log(3**0)
while(reverseThree.length!=0){
answer+=reverseThree.shift()*(3**how);
how-=1;
}
return answer;
}
1일 경우를 조심하자 !