https://school.programmers.co.kr/learn/courses/30/lessons/68935
๐ซ ์ต์ข ํ์ด
function solution(n) {
var num = n.toString(3).split("").reverse().join("")
var answer = parseInt(num, 3);
return answer;
}
์๋ฐ์คํฌ๋ฆฝํธ ์ง๋ฒ ๋ค๋ฃจ๊ธฐ
.toString(n)
๋ฌธ๋ฒ์ ํตํด n์ง๋ฒ์ ์๋ก ๋ณ๊ฒฝ ํ ์ ์๋ค.
var x = 16
x.toString(8) //20
x.toString(3) //121
x.toString(2) //10000
paseInt( x, (10์ง๋ฒ์ผ๋ก ๋ฐ๊พธ๊ณ ์ํ๋ x๊ฐ ๋ช์ง๋ฒ์ธ์ง) )
var answer = parseInt(x, 3) //16
728x90
'Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ํ๋ก๊ทธ๋๋จธ์ค - ํ๋ฒ๊ฑฐ ๋ง๋ค๊ธฐ(์๋ฐ์คํฌ๋ฆฝํธ) (0) | 2023.01.24 |
---|