๐ฅ Algorithm/Programmers
[ํ๋ก๊ทธ๋๋จธ์ค] ์์ด ๋๋ง์๊ธฐ (js)
Lennon
2021. 11. 2. 18:12
728x90
๋ฐ์ํ
https://programmers.co.kr/learn/courses/30/lessons/12981?language=javascript
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
๋ฐ์ํ