题解 | #提取不重复的整数#
提取不重复的整数
http://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
1. 将数字存储为字符串,反向遍历该字符串
2. 利用StringBuffer来去重
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); String str = sc.nextLine(); StringBuffer ans = new StringBuffer(); for(int i = str.length()-1; i>=0; i--){ if(!ans.toString().contains(str.substring(i,i+1))){ ans.append(str.substring(i,i+1)); } } System.out.println(ans.toString()); } }