Easy java solution


  • -1
    D

    public class Solution {
    public int missingNumber(int[] nums) {

        //variable to check if there is a break in the sequence
        int flag=0;
        
        //sort the array
        Arrays.sort(nums);
        
        //value to store result
        int temp=0;
        
        for(int i=0;i<nums.length;i++)
        {
            //if not in order, store missing value and break out
            if(nums[i]!=i)
            {
                flag=1;
                temp=i;
                break;
            }
        }
        
        if(flag==1)
            return temp;
        else
            return nums.length;
        
    }
    

    }


Log in to reply
 

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