题解 | #字符集合#
字符集合
https://www.nowcoder.com/practice/784efd40ed8e465a84821c8f3970b7b5
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static String func(String str) { boolean[] arr = new boolean[128]; StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if (!arr[ch]) { sb.append(ch); arr[ch] = true; } } return sb.toString(); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNextLine()) { String str = sc.nextLine(); String ret = func(str); System.out.println(ret); } } }