StringBuffer的思路
提取不重复的整数
http://www.nowcoder.com/questionTerminal/253986e66d114d378ae8de2e6c4577c1
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String input = sc.nextLine(); StringBuffer sb = new StringBuffer(input).reverse(); boolean[] exist = new boolean[10]; // 用 boolean 数组缓存,初始化全false for(int i = 0;i < sb.length(); i++) { if (exist[sb.charAt(i) - '0']) { sb.deleteCharAt(i); i--; // 删除后要指回同一位置 } else { exist[sb.charAt(i) - '0'] = true; } } System.out.println(sb.toString()); } } }