JAVA single pass


  • 2
    D
        public class Solution {
    public int missingNumber(int[] nums) {
        
        int len = nums.length;
        int result=len*(len+1)/2;
        
        for(int i=0;i<len;i++){
            result-=nums[i];
        }
       return result; 
        
    }
    

    }


Log in to reply
 

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