Notice
Recent Posts
Recent Comments
Link
ยซ   2025/01   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Lennon FE

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์˜์–ด ๋๋ง์ž‡๊ธฐ (js) ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm/Programmers

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์˜์–ด ๋๋ง์ž‡๊ธฐ (js)

Lennon 2021. 11. 2. 18:12
728x90
๋ฐ˜์‘ํ˜•

https://programmers.co.kr/learn/courses/30/lessons/12981?language=javascript 

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์˜์–ด ๋๋ง์ž‡๊ธฐ

3 ["tank", "kick", "know", "wheel", "land", "dream", "mother", "robot", "tank"] [3,3] 5 ["hello", "observe", "effect", "take", "either", "recognize", "encourage", "ensure", "establish", "hang", "gather", "refer", "reference", "estimate", "executive"] [0,0]

programmers.co.kr

 

function solution(n, words) {
    let result = [words[0],];
    let answer = 0;
    for(let i = 0; i < words.length; i++){

        if(result.includes(words[i+1])){
            answer = i+2;
            break;
        }
            
        if(i < words.length-1 && words[i][words[i].length-1] !== words[i+1][0]){
            answer = i+2;
            break;
        }
        
        result.push(words[i+1]);
    }
    
    return answer===0 ? [0,0] : [ answer%n===0 ? n : answer%n, Math.ceil(answer/n)]
}

๋‹จ์ˆœํ•œ ๊ตฌํ˜„ ๋ฌธ์ œ์ด๋‹ค.

 

์ˆœ์„œ๋‚˜ ์ฐจ๋ก€๋ฅผ ์ž˜ ์ƒ๊ฐํ•ด returnํ•˜๋ฉด ์‰ฝ๊ฒŒ ํ’€๋ฆด ์ˆ˜ ์žˆ๋‹ค.

728x90
๋ฐ˜์‘ํ˜•
Comments