Programmers, 한 번만 등장한 문자

# Level 0. 한 번만 등장한 문자

한 번만 등장한 문자

문제 설명

문자열 s가 매개변수로 주어집니다. s에서 한 번만 등장하는 문자를 사전 순으로 정렬한 문자열을 return 하도록 solution 함수를 완성해보세요. 한 번만 등장하는 문자가 없을 경우 빈 문자열을 return 합니다.

제한사항

문제 풀이

1
2
3
4
5
6
7
8
9
10
11
function solution(s) {
  let answer = "";
  const countArray = new Array(32).fill(0);
  for (let i = 0; i < s.length; i++) {
    countArray[s.charCodeAt(i) - 97]++;
  }
  countArray.forEach((count, index) => {
    if (count === 1) answer += String.fromCharCode(index + 97);
  });
  return answer;
}