Java simplest beats 100% 10ms


  • 0
    M
    public class Solution {
        public int[] findErrorNums(int[] nums) {
            int[] res = new int[2];
            int[] mark = new int[nums.length+1];
            for(int num:nums) mark[num]++;
            for(int i=1; i<mark.length; i++){
                if(mark[i] == 2) res[0] = i;
                if(mark[i] == 0) res[1] = i;
            }
            return res;
        }
    }
    

Log in to reply
 

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