01-08 08:57
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

miinsun

[Algorithm]์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ž๋ฐ”_6 ์ค‘๋ณต ๋ฌธ์ž ์ œ๊ฑฐ ๋ณธ๋ฌธ

Algorithm/Java

[Algorithm]์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ž๋ฐ”_6 ์ค‘๋ณต ๋ฌธ์ž ์ œ๊ฑฐ

miinsun 2022. 1. 2. 23:11

 

๐Ÿ’ฌ ๋ฌธ์ œ ์„ค๋ช…

์†Œ๋ฌธ์ž๋กœ ๋œ ํ•œ๊ฐœ์˜ ๋ฌธ์ž์—ด์ด ์ž…๋ ฅ๋˜๋ฉด ์ค‘๋ณต๋œ ๋ฌธ์ž๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์„ธ์š”.
์ค‘๋ณต์ด ์ œ๊ฑฐ๋œ ๋ฌธ์ž์—ด์˜ ๊ฐ ๋ฌธ์ž๋Š” ์›๋ž˜ ๋ฌธ์ž์—ด์˜ ์ˆœ์„œ๋ฅผ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค.

 

โ€‹

๐Ÿ”จ ์ž…์ถœ๋ ฅ ์˜ˆ

์ž…๋ ฅ - ์ฒซ ์ค„์— ๋ฌธ์ž์—ด์ด ์ž…๋ ฅ๋ฉ๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋Š” 100์„ ๋„˜์ง€ ์•Š๋Š”๋‹ค.

ksekkset

์ถœ๋ ฅ - ์ฒซ ์ค„์— ์ค‘๋ณต๋ฌธ์ž๊ฐ€ ์ œ๊ฑฐ๋œ ๋ฌธ์ž์—ด์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

kset

โ€‹

โ€‹

๐Ÿ’ป Solution.java

import java.util.Scanner;
  
public class Main {
	public String solution(String str) {
		String answer = "";
		
		for(int i = 0; i < str.length(); i++) {
			String ch = String.valueOf(str.charAt(i));
			if(!answer.contains(ch)) {
				answer += ch;
			}
		}
		
		return answer;
	}
	
	public static void main(String[] args){
		Main main  = new Main();
		Scanner sc =new Scanner(System.in);
		String str = sc.next();
		
		System.out.println(main.solution(str));
		sc.close();
		return ;
	}
}
Comments