๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - 3์ง„๋ฒ• ๋’ค์ง‘๊ธฐ(์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ)

by ๋…น์ฐจ๋ง›๊ฐœ๊ตฌ๋ฆฌ 2023. 3. 2.

https://school.programmers.co.kr/learn/courses/30/lessons/68935

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

๐Ÿ’ซ ์ตœ์ข…ํ’€์ด

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