image.png

解题思路

image.png

  1. class Solution {
  2. public int missingNumber(int[] nums) {
  3. int expectedSum = nums.length*(nums.length + 1)/2;
  4. int actualSum = 0;
  5. for (int num : nums) actualSum += num;
  6. return expectedSum - actualSum;
  7. }
  8. }