Java solution beats 92%


  • 0
    R

    class Solution {
    public int[] findErrorNums(int[] nums) {
    int [] re = new int[2];
    int [] numc = new int[nums.length];
    for(int i=0;i<nums.length;i++){
    numc[nums[i]-1]++;
    }
    for(int i=0;i<numc.length;i++){
    if(numc[i]==2)
    re[0]=i+1;
    if(numc[i]==0)
    re[1]=i+1;
    }
    return re;
    }
    }


Log in to reply
 

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