2ms java simple solution


  • -5
    L
    public class Solution {
        public int findDuplicate(int[] nums) {
            int len = nums.length;
            int[] array = new int[len];
            for(int j=0;j<len;j++){
                array[j] = len;
            }
            for(int i=0;i<len;i++){
                int val = nums[i];
                if(array[val-1] == len){
                    array[val-1] = val;
                    continue;
                }
                return val;
            }
            return 0;
            
        }
    }

Log in to reply
 

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