share my java solution!


  • 0
    T
    public class Solution {
        public int[] findErrorNums(int[] nums) {
            int[] hash=new int[100001];
            int findrep=-1;
            for(int i=0;i<nums.length;i++){
                if(hash[nums[i]]>0){
                    findrep=nums[i];
                }
                hash[nums[i]]++;
            }
            int findmissing=-1;
            for(int i=1;i<=nums.length;i++){
                if(hash[i]==0){
                    findmissing=i;
                    break;
                }
            }
            
            return new int[]{findrep,findmissing};
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.