elioground.

[Coding Test] 프로그래머스 -문자열 내 p와 y의 개수-.

목차
  1. 📃문제 링크
  2. 🤨생각하기
  3. 😎내 풀이

📃문제 링크

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

🤨생각하기

문제 그대로 구현

😎내 풀이

function solution(s) {
  let pCnt = 0
  let yCnt = 0
  for (const letter of s) {
    if (letter === 'p' || letter === 'P') {
      pCnt++
    } else if (letter === 'y' || letter === 'Y') {
      yCnt++
    }
  }
  if (pCnt === yCnt) {
    return true
  } else {
    return false
  }
}

이 글은 CC BY 4.0 라이선스를 따릅니다.