😎풀이

  1. s 정렬
  2. t 정렬
  3. t가 항상 한 자리 더 많으므로 t만큼 순회하며 각 자리 비교
    3-1. 자리 알파벳이 다르다면 반환
function findTheDifference(s: string, t: string): string {
    s = [...s].sort().join("")
    t = [...t].sort().join("")
    for(let i = 0; i < t.length; i++) {
        if(s[i] !== t[i]) return t[i]
    }
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글

Powered by GraphCDN, the GraphQL CDN