[백준] 그룹 단어 찾기

yoon Y·2022년 4월 20일
0

알고리즘 문풀

목록 보기
6/6

문제 링크

내 풀이

groupWordCnt에 input단어의 갯수를 저장한다.
연속되는 알파벳들 중 마지막 알파벳을 alphabetArr에 푸쉬한다.
(현재 알파벳과 다음 알파벳이 일치하지 않는 경우 현재 알파벳을 푸쉬)
푸쉬 하기 전에 현재 알파벳이 alphabetArr에 포함되는지 확인한다.
포함된다면 groupWordCnt에서 1을 감소시키고 다음 단어로 넘어간다.

const solution = () => {
  let groupWordCnt = input.shift()

  input.map((str) => {
    str = str.replace(/(\s*)/g, '')
    const alphabetArr = []

    for (let i = 0; i < str.length; i++) {
      if (!(str[i] === str[i + 1])) {
        if (alphabetArr.includes(str[i])) {
          groupWordCnt—
          break
        }
        alphabetArr.push(str[i])
      }
    }
  })
profile
#프론트엔드

0개의 댓글