题解 | #数组中只出现一次的两个数字#

数组中只出现一次的两个数字

http://www.nowcoder.com/practice/389fc1c3d3be4479a154f63f495abff8

两个集合查重

import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param array int整型一维数组 
     * @return int整型一维数组
     */
    public int[] FindNumsAppearOnce (int[] array) {
        // write code here
        int[] we =new int[2];
        int w=0;
        Set<Integer> op = new HashSet<>();
        Set<Integer> you = new HashSet<>();
        for(int i : array){
           
            if(!you.add(i)){
                op.add(i);
            }
        }
        for(int i : array){
            if(!op.contains(i)){
                we[w] = i;
                w++;
            }
        }
        if(we[0] > we[1]){
            w=we[0];
            we[0]=we[1];
            we[1]=w;
        }
        return we;
    }
}
全部评论

相关推荐

Cherrycola01:0实习 0项目 约等于啥也没有啊 哥们儿这简历认真的吗
点赞 评论 收藏
分享
迷茫的大四🐶:自信一点,我认为你可以拿到50k,低于50k完全配不上你的能力,兄弟,不要被他们骗了,你可以的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务