国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

leecode 268. Missing Number

2019-11-14 10:42:20
字體:
來源:轉載
供稿:網友

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.

Note: Your algorithm should run in linear runtime complexity. Could you implement it using only constant extra space complexity?

class Solution {public: int missingNumber(vector<int>& nums) { int n=nums.size(); int m=2*n; for(int i=0;i<n;i++) { if(nums[i]%m!=0){ nums[((nums[i]-1)%m)]+=m; } } for(int i=0;i<n;i++) { if(nums[i]<m) return i+1; } return 0; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 监利县| 昌黎县| 华池县| 阜新市| 吉林市| 仁布县| 康平县| 清丰县| 翼城县| 曲沃县| 海淀区| 吉木萨尔县| 阜新市| 镇赉县| 庄浪县| 望谟县| 石首市| 桐乡市| 泾川县| 晋中市| 榆中县| 嵊泗县| 桂东县| 西宁市| 莱芜市| 黑山县| 岳西县| 华容县| 青海省| 若尔盖县| 汾阳市| 沙河市| 商洛市| 姚安县| 平江县| 应用必备| 伊川县| 六枝特区| 高雄县| 山阴县| 朝阳市|