标签:com segment www. code turn div star als start
217. Contains Duplicate 后面3个题都是限制在1~n的
class Solution { public: bool containsDuplicate(vector<int>& nums) { int length = nums.size(); if(length <= 0) return false; sort(nums.begin(),nums.end()); for(int i = 1;i < length;i++){ if(nums[i] == nums[i-1]) return true; } return false; } };
287. Find the Duplicate Number
class Solution { public: int findDuplicate(vector<int>& nums) { int length = nums.size(); if(length <= 0) return -1; int start = 1; int end = length - 1; while(start < end){ int mid = (start + end)/2; int count = 0; for(int i = 0;i < length;i++){ if(nums[i] <= mid) count++; } if(count > mid) end = mid; else start = mid + 1; } return start; } };
http://www.cnblogs.com/grandyang/p/4843654.html
https://blog.csdn.net/xudli/article/details/48802345
https://segmentfault.com/a/1190000003817671
leetcode 217. Contains Duplicate 287. Find the Duplicate Number
标签:com segment www. code turn div star als start
原文地址:https://www.cnblogs.com/ymjyqsx/p/9656954.html