Skip to content

Latest commit

 

History

History
24 lines (22 loc) · 353 Bytes

面试题53 - II. 0~n-1中缺失的数字.md

File metadata and controls

24 lines (22 loc) · 353 Bytes
func missingNumber(nums []int) int {
   n := len(nums)
   sum := (n+n*n)>>1
   for _, v :=range nums{
      sum -= v
   }
   return sum
}

func missingNum(nums []int) int {
   i, j := 0, len(nums)-1
   for i <= j {
      mid := (i+j)>>2
      if nums[mid] == mid {
         i = mid+1
      }else {
         j = mid
      }
   }
   return i
}