728x90
SMALL

using System;
using System.Linq;
using System.Collections.Generic;

public class Solution {
    public string solution(string s) {
        string answer = "";
        int count = 0;
        int j =0;
        
        for(int i=0;i<s.Length;i++)
        {
            for(j=0;j<s.Length;j++)
            {
                if(s[i] == s[j])
                {
                    count++;
                }    
            }
            
            if(count == 1)
                {
                    answer += s[i];
                }
                count = 0;    
        }
        answer = string.Concat(answer.OrderBy(x => x));   
        return answer;
    }
}

 

//뭔가 이상하다

 

using System;
using System.Linq;

public class Solution {
    public string solution(string s) {
        string answer = string.Concat(s.Where(x => s.Count(o => o == x) == 1).OrderBy(x => x));
        return answer;
    }
}

 

파이썬

//////

 

def solution(s):
    answer = ''
    for c in 'abcdefghijklmnopqrstuvwxyz':
        if s.count(c) == 1:
            answer += c
    return answer

 

///////////

 

def solution(s):
    answer = "".join(sorted([ ch for ch in s if s.count(ch) == 1]))
    return answer

 

자바

//////

 

class Solution {
    public String solution(String s) {
        int[] alpha = new int[26];
        
        for(char c : s.toCharArray())
        {
            alpha[c - 'a']++;
        }

        StringBuilder answer = new StringBuilder();
        
        for(int i = 0; i < 26; i++)
        {
            if(alpha[i] == 1)
            {
                answer.append((char)(i + 'a'));
            }
        }
        return answer.toString();
    }
}

 

 

import java.util.*;

class Solution {
    public String solution(String s) {

        HashSet<String> set = new HashSet<>();

        for (int i = 0; i < s.length(); i++) {
            String replace = s.replace(s.charAt(i) + "", "");
            if(s.length() - replace.length() == 1){
                set.add(s.charAt(i)+"");
            }
        }
        ArrayList<String> list = new ArrayList<>(set);
        Collections.sort(list);
        return String.join("", list);
    }
}

 

728x90

설정

트랙백

댓글