数组nums包含从0到n的所有整数,但其中缺了一个。请编写代码找出那个缺失的整数。你有办法在O(n)时间内完成吗?
示例 1:
输入:[3,0,1] 输出:2
示例 2:
输入:[9,6,4,2,3,5,7,0,1]
输出:8
public class FindMissingNumber { public static void main(String[] args) { int nums[]={0,1,3,2,5}; int sum=0;//数组的和 int add=0;//{0,1,2,3}的和 for(int i=0;i<nums.length;i++){ sum=nums[i]+sum; add=add+i;//利用0到n的特性 } add=add+nums.length;//加最后一个元素 int result=add-sum; System.out.println(result); } }
acheter cialis en belgique https://bbuycialisss.com/ – best place to buy cialis online reviews Buy Wellbutrin Xl No Prescription Cialis Canadian Health Care Mall
Cialis Duree Action obegreeRof https://bbuycialisss.com/# – buy liquid cialis online Altele venta viagra mendoza PafGrade Cialis UnsoneeLetty viagra cialis walmart
Cialis Para Hipertensos Wicmymmele https://artsocialist.com/ – cialis dosage gaideleplete Cialis Billig Kaufen Ohne Rezept affextop generic cialis online adoreakder Tab online isotretinoin delivered on saturday Florida
Viagra Per Ragazzi Wicmymmele cialis 20mg for sale gaideleplete How To Buy Amoxicilina Without Dr Approval
https://vsdoxycyclinev.com/ – buy doxycycline uk
buy real cialis online
I got this web page from my pal who told me concerning this web
page and at the moment this time I am visiting this website and reading very informative posts here.
https://bestadalafil.com/ – Cialis Hqzjjj Analgesics and fever reduction may be appropriate. Quien Vende Cialis Ouqukn Cialis efectos del viagra Cblyxh https://bestadalafil.com/ – Cialis Levitra Dana El Higado Fncfps