class Solution {
fun solution(s: String): String {
val mut = mutableListOf<Char>()
val cnt = mutableListOf<Int>()
var answer: String = ""
for(i in s.toSet()) mut.add(i)
for(i in 0 until mut.size) cnt.add(0)
for(i in s.toList()) if(i in mut.sorted()) cnt[mut.sorted().indexOf(i)] += 1
for(i in 0 until cnt.size) if(cnt[i] == 1) answer += mut.sorted()[i]
return answer
}
}
mut 와 cnt 로 중복을 제거하고 원래의 문자열에서 개수를 카운트 후
요소가 1인 인덱스를 통해서 mut의 요소를 꺼내서 answer 에 붙인다
s.toSet().filter { unique -> s.count { i -> i == unique } == 1 }
.sorted().joinToString("")
ex)
val s = "hello"
toSet() 함수로 중복 요소를 제거
이 list에서 한 번만 등장한 문자를 찾아서 반환해야 하므로
원래 문자열과 중복을 제거한 요소들을 대상으로 count 하여 갯수가 1인 요소들만
filter로 조건을 걸어서 정렬 후 반환한다