Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.
For example,
Given nums = [0, 1, 3] return 2.
從0開始到n,找出中間丟失的一個(gè)數(shù)字。
代碼1:排序后逐個(gè)遍歷~

參考代碼1
思路:排好序之后,對(duì)比數(shù)組位置i和數(shù)組位置上的數(shù)值nums[i],如果不等直接返回這個(gè)位置,如果到最后都沒找到,說明沒有丟失,則直接返回?cái)?shù)組長(zhǎng)度。
代碼2:利用等差數(shù)列求和去計(jì)算

參考代碼
解題思路你懂得。