算法刷题200道LeetCode
追风少年dream
视频编码,游戏开发
展开
-
数组(1):Remove Duplicates from Sorted Array
描述:Given a sorted array, remove the duplicates in place such that each element appear only onceand return the new length.Do not allocate extra space for another array, you must do this in place wi...原创 2018-04-01 10:28:39 · 196 阅读 · 0 评论 -
数组(16):加一
66.加一 描述: https://leetcode-cn.com/problems/plus-one/description/分析:加法运算最优解:class Solution {public: vector<int> plusOne(vector<int>& digits) { int n = digits....原创 2018-06-05 11:00:32 · 285 阅读 · 0 评论 -
数组(15):旋转图像
48 . 旋转图像 描述: https://leetcode-cn.com/problems/rotate-image/description/分析: 顺时针旋转可以理解为,首先沿着副对角线翻转一次,然后沿着水平中线翻转一次 或者,首先沿着主对角线翻转一次,再沿着水平中线翻转一次解法1:class Solution {public: void rotate...原创 2018-06-05 10:43:11 · 305 阅读 · 0 评论 -
数组(14):容器盛水最多系列
11 . 盛最多水的容器给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) 。画 n 条垂直线,使得垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0)。找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。注意:你不能倾斜容器,n 至少是2。最优解:class Solution {public: in...原创 2018-06-05 10:36:45 · 523 阅读 · 0 评论 -
数组(13):数独
36 . Valid Sudoku 描述:Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:Each row must contain the digits 1-9 without repetitio...原创 2018-06-05 09:47:16 · 659 阅读 · 0 评论 -
数组(12):leetcode 中的排列问题
31.Next Permutation ,解法见上一篇博客; 46.全排列 描述:Given a collection of distinct numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3...转载 2018-06-03 17:29:02 · 266 阅读 · 0 评论 -
数组(11):下一个排列
描述: 31. Next Permutation Total Accepted: 54346 Total Submissions: 212155 Difficulty: Medium Implement next permutation, which rearranges numbers into the lexicographically next greater permutation ...转载 2018-05-08 16:28:02 · 270 阅读 · 0 评论 -
数组(10):Remove Element
描述: Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn’t matter what you leave beyond the new length....原创 2018-05-03 19:59:39 · 188 阅读 · 0 评论 -
数组(9):4Sum
描述: 给定一个包含 n 个整数的数组 nums 和一个目标值 target,判断 nums 中是否存在四个元素 a,b,c 和 d ,使得 a + b + c + d 的值与 target 相等?找出所有满足条件且不重复的四元组。注意:答案中不可以包含重复的四元组。分析: 先排序,然后左右夹逼,时间复杂度为O(n^3),空间复杂度O(1);代码:class Solut...原创 2018-04-23 20:59:45 · 259 阅读 · 0 评论 -
数组(8):3Sum Closest
描述:Given an array S of n integers, find three integers in S such that the sum is closest to a given number,target. Return the sum of the three integers. You may assume that each input would have ...原创 2018-04-02 17:04:53 · 214 阅读 · 0 评论 -
数组(7):3Sum
描述:Given an array S of n integers, are there elements a,b,c in S such that a + b + c = 0? Find all uniquetriplets in the array which gives the sum of zero.Note:• Elements in a triplet (a,b,c) m...原创 2018-04-02 16:48:35 · 170 阅读 · 0 评论 -
数组(6):Two Sum
描述:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target,...原创 2018-04-02 15:51:46 · 203 阅读 · 0 评论 -
数组(5):Longest Consecutive Sequence
描述:Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example, Given [100, 4, 200, 1, 3, 2], The longest consecutive elements sequence is [1,2, ...转载 2018-04-02 15:16:54 · 213 阅读 · 0 评论 -
数组(4):Search in Rotated Sorted Array II
描述:Follow up for ”Search in Rotated Sorted Array”: What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the...原创 2018-04-01 21:02:21 · 196 阅读 · 0 评论 -
数组(3):Search in Rotated Sorted Array
描述:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array return...原创 2018-04-01 20:34:54 · 203 阅读 · 0 评论 -
数组(2):Remove Duplicates from Sorted Array II
描述:Follow up for ”Remove Duplicates”: What if duplicates are allowed at most twice?For example, Given sorted array A = [1,1,1,2,2,3],Your function should return length = 5, and A is now [1,1,2,2...原创 2018-04-01 11:21:07 · 270 阅读 · 0 评论 -
数组(17):爬楼梯问题
70.爬楼梯 描述: https://leetcode-cn.com/problems/climbing-stairs/description/分析: 设f(n)表示爬n阶楼梯的不同方法数,为了爬到第n阶楼梯,有两个选择: 从第n-1阶前进一步 从第n-1阶前进2步 因此,有f(n)=f(n-1)+f(n-2); 这是一个斐波那契数列。 因此可以用迭代或者数学公式的方法...原创 2018-06-05 11:39:39 · 430 阅读 · 0 评论