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

提取不重复的整数

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

input(int) -> 字符串数组 -> 逆序添加到新的字符串out -> output(int)

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int input = sc.nextInt();
        int output = new Solution().update(input);
        System.out.println(output);
    }
}

class Solution {
    public int update(int num) {
        String string = num + "";
        String[] str = string.split("");
        String out = "";
        for (int i = str.length - 1; i >= 0; i--) {
            if (!out.contains(str[i])) {
                out = out + str[i];
            }
        }
        int result = Integer.parseInt(out);
        return result;
    }
}
全部评论

相关推荐

程序员小白条:找的太晚,别人都是大三实习,然后大四秋招春招的,你大四下了才去实习,晚1年
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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