Only one missing number,sum(0...n) - sum(nums[i])


  • 0
    S
    public class Solution {
        public int MissingNumber(int[] nums) {
            int n = nums.Length;
            int t = 0;
            for(int i=0;i<n;i++) {
                t = t+i-nums[i];
            }
            t = t + n;
            return t;
        }
    }

Log in to reply
 

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