![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数组
益达915
一名在读大学生,渣渣一枚,进取中...
展开
-
去除数组中重复元素
类型总结:双指针问题 说明:遍历时利用2个下标,边遍历边更新。1、26.Remove Duplicates from Sorted Array 从一个包含重复元素的数组里面去除重复的元素,要求不能另外开辟空间思路:由于是一个经过排序的数组,可以设置一个临时变量,从第1个元素(起始是0个)开始遍历,如果遇到不同的,就将其赋值。并且当前index++,存入新的点。遇到相同的这些都不会发生。一开始我想原创 2016-07-29 10:01:36 · 1255 阅读 · 0 评论 -
从有序数组中寻找元素
类型总结:二分 说明:利用数组有序的性质,使用二分实现快速查找3、33. Search in Rotated Sorted Array 题目的大意是一个顺序的数组,但是在某个地方被反转了,例如 (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). 那么给出一个数,问找到这个数的下标。 实际上是一个变相的二分,只是在进行二分之前,不能仅仅按照ta原创 2016-07-29 10:15:02 · 432 阅读 · 0 评论 -
求和
主要思想:哈希 双指针 内容:用unordered_map来改善哈希表的性能5、128. Longest Consecutive Sequence Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example, Given [100, 4原创 2016-07-29 19:35:22 · 326 阅读 · 0 评论 -
求数组中多个数相加等于某一值
主要思想:排序+两端逼近 内容:排序使得整个数组有序从而可以使用双指针从数组的两端向中间逼近所需要的值7、3Sum 顾名思义,求数组中3个数相加等于某一特定的数自己写了一个似乎是O(n^2) 汗颜 在Two Sum的引导下,我成功使用了unordered_map 然而在run code的时候就发现了一个无法解决的问题: Your input [-1,0,1,2,-1,-4] Your a原创 2016-07-29 19:41:36 · 19073 阅读 · 0 评论 -
数学和模拟
思想:利用数学规律或者模拟 内容:注意next_permutation的求取方式 Trapping Rain Water和Candy的单调方式 Single Num涉及到的位运算 11、Next Permutation 纯数学题,/(ㄒoㄒ)/~~class Solution {public: void nextPermutation(vector<int>& nums) {原创 2016-07-30 18:04:23 · 457 阅读 · 0 评论 -
LeetCode | Minimum Size Subarray Sum
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given the array [2,3原创 2016-09-01 00:00:17 · 305 阅读 · 0 评论