C++
IMapMap
这个作者很懒,什么都没留下…
展开
-
LeetCode : Single Number
第一种方法,用哈希表。map<int, int>ary; for (int i = 0; i < n; i++) { if (ary.find(A[i]) == ary.end()) ary.insert(pair<int, int>(A[i], i)); else ary.erase(A[i]); } map<int, int>::iterator原创 2015-03-16 10:47:09 · 327 阅读 · 0 评论 -
LeetCode : Remove Duplicates from Sorted Array
常规方法是使用双指针。int removeDuplicates(vector<int>& nums) { if(nums.size() < 2) return nums.size(); int left = 1; while(left < nums.size()) { if(nums[left] == nums[left - 1])原创 2016-09-27 19:00:03 · 263 阅读 · 0 评论 -
LeetCode : Majority Element
思路1数组经过快速排序,返回数组中间的值。超时。(直接使用sort函数会通过,而且比哈希表快)void myQuickSort(vector<int>& nums, int begin, int end) { if(begin < end) { int l = begin, r = end; int flag = nums[l]; whi原创 2016-09-29 20:50:23 · 239 阅读 · 0 评论 -
一个模拟问题
ProblemJesse is building his own operating system and now faces the task of building the process scheduling and the memory management feature. He has laid down the rules of how he is going to do it. It原创 2016-09-29 19:19:03 · 307 阅读 · 0 评论