O(nlgn) simple java solution


  • 0
    L
    public class Solution {
        public int missingNumber(int[] nums) {
            Arrays.sort(nums);
            for(int i = 0 ; i < nums.length ; i++)
            {
                if(nums[i] != i){
                    return i;
                }
            }
    
             return nums[0] == 0? nums[nums.length-1]+1 : 0;
        }
    }

Log in to reply
 

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