import java.util.HashSet;
import java.util.Set;

class Solution {
    public String solution(String my_string) {
        Set<Character> set = new HashSet<>();
        StringBuilder sb = new StringBuilder();

        for(int i = 0; i < my_string.length(); i++) {
            char c = my_string.charAt(i);
            if(!set.contains(c)) {  // Set에 이미 있으면 추가 X
                set.add(c);
                sb.append(c);
            }
        }
        return sb.toString();
    }
}
profile
I'm still hungry.

0개의 댓글