标签:iss number += div ssi solution span for res
268 Missing Number class Solution { public int missingNumber(int[] nums) { int target = nums.length * (nums.length + 1) / 2; int sum = 0; for(int i = 0; i < nums.length; i++){ sum += nums[i]; } int result = target - sum; return result; } } Bs class Solution { public int missingNumber(int[] nums) { Arrays.sort(nums); int left = 0; int right = nums.length - 1; while( left <= right){ int mid = left + (right - left) / 2; if(nums[mid] > mid){ right = mid - 1; }else{ left = mid + 1; } } return left; } }
标签:iss number += div ssi solution span for res
原文地址:https://www.cnblogs.com/tobeabetterpig/p/9451000.html