题解 | #提取不重复的整数#

提取不重复的整数

http://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1

要点是去重复值,要求留下的数值有序,而且不能重复,符合list集合的存储特点,采用ArrayList集合逐个循环反向添加元素即可。

import java.util.Scanner;
import java.util.ArrayList;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        char[] charArray = str.toCharArray();
        ArrayList<Character> arrayList = new ArrayList<Character>();
        for (int i = charArray.length - 1; i >= 0; i--) {
            if (!arrayList.contains(charArray[i])){
                arrayList.add(charArray[i]);
            }
        }
        for (Character ch : arrayList) {
            System.out.print(ch);
        }
        sc.close();
    }
}


全部评论

相关推荐

不愿透露姓名的神秘牛友
06-25 17:22
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务