프로그래머스 - 영어 끝말잇기

이서현·2021년 7월 28일
0

Algorithm

목록 보기
52/76

07.28에 푼 문제입니당🌷
영어 끝말잇기
간단한 문제이다!
조건만 잘 처리하면 된다

function solution(n, words) {
    var answer = [];
    let count = 0
    let ex=''
    for(let i=0;i<words.length;i++){
        const word =words[i]
        if(i===0){
            ex=word[word.length-1]
            answer.push(word)
            continue
        }

        if(ex!==word[0]){
            return [i%n+1,Math.floor(i/n)+1]
        }

        if(answer.includes(word)){
            return [i%n+1,Math.floor(i/n)+1]
        }
        ex=word[word.length-1]
        answer.push(word)
    }

    return [0,0];
}
profile
안녕하세요. 이서현입니다( ღ'ᴗ'ღ )

0개의 댓글