two pointers
i-Blue
抱平常心走平常路
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
349. Intersection of Two Arrays
Tags- binary search, hash table, two pointers, sort 方法一:sort+binary search 先对nums1、nums2从小到大排序,然后,对于nums2中不同的元素,我们在nums1中二分搜索,看看是否存在。 这里注意,nums2中的元素是排过序的,所以没有必要每个元素都在(0, nums1.size()-1)中二分搜索。比如,num原创 2016-08-19 15:33:29 · 319 阅读 · 0 评论 -
3Sum Closest
tags:two pointers 解法思想见:http://www.sigmainfy.com/blog/summary-of-ksum-problems.html 代码: class Solution { public: int threeSumClosest(vector& nums, int target) { sort(nums.begin(), nums.原创 2016-08-23 21:59:07 · 239 阅读 · 0 评论 -
4Sum
tags: hash table、two pointers k-sum问题都是一类问题。 最经典的是2-sum,用two pointers在线性时间内解决。 至于3sum、4sum问题,都可以先将问题分解,然后在用2sum的方法解决。2sum时间复杂度O(N^2),3sum时间复杂度O(N^3)。 具体见:http://www.sigmainfy.com/blog/summary-of-k原创 2016-09-03 18:58:08 · 584 阅读 · 0 评论 -
27. Remove Element-two pointers
Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory.原创 2016-09-26 20:09:54 · 306 阅读 · 0 评论 -
26. Remove Duplicates from Sorted Array(删除已排序数组中的重复数)-two pointers
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place with原创 2016-11-07 20:32:14 · 337 阅读 · 0 评论 -
287. Find the Duplicate Number--binary search/快慢指针
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, fi原创 2017-02-18 20:55:27 · 616 阅读 · 0 评论
分享