Deep_Dev

๋ฌธ์ œ ์„ค๋ช…

๋ฌธ์ž์—ด my_string์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. my_string์—์„œ ์ค‘๋ณต๋œ ๋ฌธ์ž๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ํ•˜๋‚˜์˜ ๋ฌธ์ž๋งŒ ๋‚จ๊ธด ๋ฌธ์ž์—ด์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

 
์ œํ•œ์‚ฌํ•ญ
  • 1 ≤ my_string ≤ 110
  • my_string์€ ๋Œ€๋ฌธ์ž, ์†Œ๋ฌธ์ž, ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
  • ๋Œ€๋ฌธ์ž์™€ ์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•ฉ๋‹ˆ๋‹ค.
  • ๊ณต๋ฐฑ(" ")๋„ ํ•˜๋‚˜์˜ ๋ฌธ์ž๋กœ ๊ตฌ๋ถ„ํ•ฉ๋‹ˆ๋‹ค.
  • ์ค‘๋ณต๋œ ๋ฌธ์ž ์ค‘ ๊ฐ€์žฅ ์•ž์— ์žˆ๋Š” ๋ฌธ์ž๋ฅผ ๋‚จ๊น๋‹ˆ๋‹ค.

 

 

์ž…์ถœ๋ ฅ ์˜ˆ    my_string    // result
"people" "peol"
"We are the world" "We arthwold"

 

 


๋นˆ ๋ฌธ์ž์—ด answer์— ํ•ด๋‹น ์ž…๋ ฅ ๋ฌธ์ž์—ด์ด ์—†์œผ๋ฉด ์ถ”๊ฐ€

!contains ===> ( charํ˜•์ด๋‹ˆ๊นŒ String์œผ๋กœ ํ˜•๋ณ€ํ™˜ํ•ด์„œ )


class Solution {
    public String solution(String my_string) {
        String answer = "";
        for(char x:my_string.toCharArray()){
            if(!answer.contains(String.valueOf(x)))
                answer+=x;
        }
        return answer;
    }
}