![](https://img-blog.csdnimg.cn/20181203220632447.jpg?x-oss-process=image/resize,m_fixed,h_224,w_224)
leetcode算法刷题
文章平均质量分 72
找工作之前,以为不走算法路线,就可以与算法说拜拜。然而经历了人生中第一波秋招后,发现,数据结构与算法才是构造知识大厦的根基。亡羊补牢,为时不晚。虽然错过了秋招,但我还有一次春招的机会。创此专栏,一是记录刷题的思路,二是希望像我一样0offer的同学坚定信心,天道只酬勤!
凌凌小博客
一直,一直,一直努力的用汗水去浇灌梦想开出奇迹!
为什么要努力?
因为我是凌王啊!!!
展开
-
46. 全排列
46. 全排列1. 题目题目链接2. 题目分析没有重复的数字,说明不需要考虑结果中出现重复的数字排列。依题可知,需要遍历找到所有的排列结果,知道目的后,根据所学的算法,可以很快锁定方案:回溯法。3. 解题思路4. 代码实现(java)class Solution { private List<List<Integer>> result; public List<List<Integer>> permute(int[] nums.原创 2020-11-09 01:05:53 · 161 阅读 · 0 评论 -
234. 回文链表
234. 回文链表我胡汉三又回来了,时隔一年零三个月,清晰记得去年七月份毕业入职人生第一份正式工作,凭借刷算法,刷基础,以及刷面经,在当时还算找到一份满意的工作。因为部分原因,希望换个工作环境,呼吸新鲜空气。所以重拾算法,重拾基础,重拾面经,所以2021新年伊始,可以得到一份让自己满意的工作,与君共勉!!!其实已经回归两个星期了,只是之前忙着刷题,没有写博客记录,工作后,越来越发现,好记性不如烂笔头,所以再次写博客,并且希望自己能坚持把刷题记录,以及基础准备都梳理出来。1. 题目题目链接2..原创 2020-11-04 01:23:11 · 744 阅读 · 0 评论 -
279. Perfect Squares
279. Perfect Squares 1. 题目题目链接Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n.Example 1:Input: n = 12Output: 3Explanati...原创 2019-01-28 23:52:17 · 145 阅读 · 0 评论 -
646. Maximum Length of Pair Chain
646. Maximum Length of Pair Chain 1. 题目题目链接You are given n pairs of numbers. In every pair, the first number is always smaller than the second number.Now, we define a pair (c, d) can follow anoth...原创 2019-01-28 22:49:31 · 217 阅读 · 0 评论 -
413. 等差数列划分
413. 等差数列划分1. 题目描述题目链接如果一个数列至少有三个元素,并且任意两个相邻元素之差相同,则称该数列为等差数列。例如,以下数列为等差数列:1, 3, 5, 7, 97, 7, 7, 73, -1, -5, -9以下数列不是等差数列。1, 1, 2, 5, 7数组 A 包含 N 个数,且索引从0开始。数组 A 的一个子数组划分为数组 (P, Q),P 与 Q 是整数...原创 2018-12-13 20:02:57 · 341 阅读 · 2 评论 -
300. Longest Increasing Subsequence
300. Longest Increasing Subsequence 1. 题目300. Longest Increasing SubsequenceGiven an unsorted array of integers, find the length of longest increasing subsequence.Example:Input: [10,9,2,5,3,7,10...原创 2019-02-16 12:48:31 · 148 阅读 · 0 评论 -
209. Minimum Size Subarray Sum
209. Minimum Size Subarray Sum1. 题目209. Minimum Size Subarray SumGiven an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ...原创 2019-02-16 12:42:59 · 194 阅读 · 0 评论 -
153. Find Minimum in Rotated Sorted Array
153. Find Minimum in Rotated Sorted Array 1. 题目153. Find Minimum in Rotated Sorted ArraySuppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,...原创 2019-02-16 11:34:53 · 164 阅读 · 0 评论 -
349. Intersection of Two Arrays
349. Intersection of Two Arrays 1. 题目349. Intersection of Two ArraysGiven two arrays, write a function to compute their intersection.Example 1:Input: nums1 = [1,2,2,1], nums2 = [2,2]Output: [2]...原创 2019-02-16 11:06:17 · 154 阅读 · 0 评论 -
718. Maximum Length of Repeated Subarray
718. Maximum Length of Repeated Subarray 1. 题目718. Maximum Length of Repeated SubarrayGiven two integer arrays A and B, return the maximum length of an subarray that appears in both arrays.Exampl...原创 2019-02-16 10:32:19 · 182 阅读 · 0 评论 -
392. Is Subsequence
392. Is Subsequence 1. 题目392. Is SubsequenceGiven a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t. t is pote...原创 2019-02-16 10:24:13 · 275 阅读 · 0 评论 -
组合总和问题---39. Combination Sum && 40. Combination Sum II && 216. Combination Sum III
组合总和问题—39. Combination Sum &amp;&amp; 40. Combination Sum II &amp;&amp; 216. Combination Sum III 一、给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合1. 题目39. Combination Su...原创 2019-02-15 23:38:33 · 264 阅读 · 0 评论 -
排列问题---46. Permutations && 47. Permutations II
排列问题—46. Permutations && 47. Permutations II 一、不包含重复元素的集合,列出所有排列组合1. 题目46. PermutationsGiven a collection of distinct integers, return all possible permutations.Example:Input: [1,2,3]O...原创 2019-02-10 23:54:38 · 154 阅读 · 0 评论 -
子集问题---78. Subsets && 90. Subsets II
子集问题—78. Subsets &amp;amp;amp;&amp;amp;amp; 90. Subsets II 一、不包含重复元素的集合,列出所有子集##1. 题目78. SubsetsGiven a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must no...原创 2019-02-10 23:26:56 · 255 阅读 · 0 评论 -
1108. IP 地址无效化
1108. IP 地址无效化 1. 题目题目链接2. 题目分析3. 解题思路可以手动遍历,然后替换字符串。也可以通过正则表达式,或者直接调用java的api,replaceAll方法,需要注意的是正则表达式中各种标点符号具有特殊意义,需要添加反斜杠号进行转义。4. 代码实现(java)class Solution { public String defangIPaddr(...原创 2019-08-03 23:59:25 · 335 阅读 · 0 评论 -
1021. 删除最外层的括号1021. 删除最外层的括号
1021. 删除最外层的括号1021. 删除最外层的括号 1. 题目题目链接2. 题目分析题目这么长,意思就是将每一组的括号的最外层一对括号去除,保存里面的括号组成新的字符串。3. 解题思路方法一:像这种括号匹配,如果写过计算器功能的算法,就知道需要使用栈来匹配每一对括号。遍历括号字符串S时,用startIndex记录每一组原语的第一个"("的下标,用endIndex记录原...原创 2019-08-03 23:55:14 · 374 阅读 · 0 评论 -
617. 合并二叉树
617. 合并二叉树 1. 题目题目链接2. 题目分析合并两个二叉树,如果重复的就两个节点的值加起来。3. 解题思路本题主要考验对二叉树的遍历。二叉树的遍历就两种,一是递归,二是迭代。递归遍历两个二叉树就好了。4. 代码实现(java)class Solution { public TreeNode mergeTrees(TreeNode t1, TreeNode t2...原创 2019-08-03 23:25:51 · 174 阅读 · 0 评论 -
461. 汉明距离
461. 汉明距离 1. 题目题目链接2. 题目分析计算两个数字对应二进制位不同的位置的数目,这题比较简单,正常的思维的是,将两个数字先转化成二进制,然后逐一比较统计不同的二进制位数。这种方法的时间复杂度log2X + log2Y + n;另一种方法:先求x和y异或运算的值xor,然后求出xor的二进制中的1的个数,即是x和y的二进制不同的数的个数,这个方法的时间复杂度是主要在计算x...原创 2019-08-03 23:11:51 · 219 阅读 · 0 评论 -
724. 寻找数组的中心索引
724. 寻找数组的中心索引1. 题目题目链接给定一个整数类型的数组 nums,请编写一个能够返回数组“中心索引”的方法。我们是这样定义数组中心索引的:数组中心索引的左侧所有元素相加的和等于右侧所有元素相加的和。如果数组不存在中心索引,那么我们应该返回 -1。如果数组有多个中心索引,那么我们应该返回最靠近左边的那一个。示例 1:输入:nums = [1, 7, 3, 6, 5, ...原创 2019-05-16 23:53:10 · 220 阅读 · 0 评论 -
515. 在每个树行中找最大值
515. 在每个树行中找最大值1. 题目题目链接2. 题目分析找出二叉树中每一行中的最大值,如果知道二叉树的层次遍历的实现过程,那么这题肯定so easy。3. 解题思路根据二叉树的层次遍历bfs思路,即,因为队列是先进先出的数据结构,所以可以通过使用一个队列保存每一行的节点,然后找出这一行的最大值。4. 代码实现(java)/** * Definition for a bi...原创 2019-04-19 21:10:58 · 411 阅读 · 0 评论 -
114. 二叉树展开为链表
114. 二叉树展开为链表 开篇闲话:之前一直准备春招,感觉刷题后,补博客很耗时间,所以中断博客记录刷题历程。2019.4.11拿到拼多多offer已经过去一个星期了,也是躺着放松了一星期,今天开始继续刷leetcode,希望自己可以保持对算法的敏感度,同时继续开启刷题写博客的模式,菜鸡加油。因为太菜,又过了一星期没动过脑子,所以挑了两题深度遍历的二叉树相关题目练手,思路比较明显直接,两题...原创 2019-04-19 21:06:07 · 159 阅读 · 0 评论 -
528. 按权重随机选择
528. 按权重随机选择 1. 题目题目链接给定一个正整数数组 w ,其中 w[i] 代表位置 i 的权重,请写一个函数 pickIndex ,它可以随机地获取位置 i,选取位置 i 的概率与 w[i] 成正比。说明:1 <= w.length <= 100001 <= w[i] <= 10^5pickIndex 将被调用不超过 10000 次示例1:输...原创 2019-04-11 16:46:08 · 2164 阅读 · 0 评论 -
旋转排序数组问题---153. 寻找旋转排序数组中的最小值&&33. 搜索旋转排序数组&&81. 搜索旋转排序数组 II
开篇闲话,由于忙于准备找工作,其实我是有每天刷算法题的,但感觉写博客很耗时间,所以一直没有在博客中记录。春招找的让我差点得抑郁症了,贼难受。投了40多家公司了,但目前只有六七家提供了笔试机会,学历以及自己简历的项目经历没有优势,另外互联网寒冬更是雪上加霜。。。许愿:希望春招能拿个让自己满意的offer!!!哈哈哈,开始迷信一把了!!!旋转排序数组问题—153. 寻找旋转排序数组中的最小值&am...原创 2019-03-20 22:07:10 · 300 阅读 · 0 评论 -
448. Find All Numbers Disappeared in an Array && 442. Find All Duplicates in an Array
给定一个整数数组 a,其中1 ≤ a[i] ≤ n (n为数组长度), 有些元素时重复出现的。找出重复出现的元素或者找出缺失的元素,这其实是同一个问题,只是换个说法而已。所以把这两题放到一起整理。448. Find All Numbers Disappeared in an Array 1. 题目448. Find All Numbers Disappeared in an ArrayG...原创 2019-02-19 22:04:51 · 219 阅读 · 0 评论 -
154. Find Minimum in Rotated Sorted Array II
154. Find Minimum in Rotated Sorted Array II 1. 题目154. Find Minimum in Rotated Sorted Array IISuppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., ...原创 2019-02-16 15:28:39 · 313 阅读 · 1 评论 -
164. Maximum Gap
164. Maximum Gap 1. 题目Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Return 0 if the array contains less than 2 elements.Example 1:Input:...原创 2019-01-19 20:08:37 · 247 阅读 · 0 评论 -
148. Sort List
在家就是堕落的温床,哎,没心思学习,另外又冷不想动,,,,148. Sort List 1. 题目Sort a linked list in O(n log n) time using constant space complexity.Example 1:Input: 4-&gt;2-&gt;1-&gt;3Output: 1-&gt;2-&gt;3-&gt;4Example 2:...原创 2019-01-19 17:42:24 · 132 阅读 · 0 评论 -
324. Wiggle Sort II
324. Wiggle Sort II1. 题目描述题目链接Given an unsorted array nums, reorder it such that nums[0] &lt; nums[1] &gt; nums[2] &lt; nums[3]…Example 1:Input: nums = [1, 5, 1, 1, 6, 4]Output: One possible an...原创 2019-01-06 21:51:59 · 129 阅读 · 0 评论 -
343. Integer Break
343. Integer Break 1. 题目题目链接Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get....原创 2019-01-28 17:10:02 · 271 阅读 · 0 评论 -
62. Unique Paths
62. Unique Paths 1. 题目题目链接A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time. The ro...原创 2019-01-28 16:35:21 · 105 阅读 · 0 评论 -
96. Unique Binary Search Trees
96. Unique Binary Search Trees 1. 题目题目链接Given n, how many structurally unique BST’s (binary search trees) that store values 1 … n?Example:Input: 3Output: 5Explanation:Given n = 3, there are a...原创 2019-01-28 16:15:12 · 408 阅读 · 0 评论 -
95. Unique Binary Search Trees II
95. Unique Binary Search Trees II 1. 题目题目链接Given an integer n, generate all structurally unique BST’s (binary search trees) that store values 1 … n.Example:Input: 3Output:[[1,null,3,2],[3,2,...原创 2019-01-28 15:27:34 · 127 阅读 · 0 评论 -
931. Minimum Falling Path Sum
931. Minimum Falling Path Sum 1. 题目题目链接Given a square array of integers A, we want the minimum sum of a falling path through A.A falling path starts at any element in the first row, and chooses o...原创 2019-01-28 14:10:32 · 254 阅读 · 0 评论 -
322. Coin Change--硬币找零钱问题
硬币找零钱问题 Coin Change##一、##1. 题目2. 题目分析3. 解题思路4. 代码实现(java)##二 、##1. 题目2. 题目分析3. 解题思路4. 代码实现(java)##三、##1. 题目2. 题目分析3. 解题思路4. 代码实现(java)##四、##1. 题目2. 题目分析3. 解题思路4. 代码实现(ja...原创 2019-01-25 00:29:08 · 715 阅读 · 0 评论 -
860. Lemonade Change
860. Lemonade Change 1. 题目At a lemonade stand, each lemonade costs $5.Customers are standing in a queue to buy from you, and order one at a time (in the order specified by bills).Each customer wi...原创 2019-01-23 23:59:06 · 89 阅读 · 0 评论 -
303. Range Sum Query - Immutable
303. Range Sum Query - Immutable 1. 题目Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2...原创 2019-01-23 23:39:29 · 98 阅读 · 0 评论 -
767. Reorganize String
767. Reorganize String 1. 题目Given a string S, check if the letters can be rearranged so that two characters that are adjacent to each other are not the same.If possible, output any possible result...原创 2019-01-20 22:14:35 · 233 阅读 · 0 评论 -
75. Sort Colors
75. Sort Colors 1. 题目Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.H...原创 2019-01-19 20:32:14 · 180 阅读 · 0 评论 -
179. Largest Number
179. Largest Number1. 题目描述题目链接Given a list of non negative integers, arrange them such that they form the largest number.Given a list of non negative integers, arrange them such that they form th...原创 2019-01-06 00:30:25 · 280 阅读 · 0 评论 -
731. My Calendar II
731. My Calendar II1. 题目描述题目链接Implement a MyCalendar class to store your events. A new event can be added if adding the event will not cause a double booking.Your class will have the method, book...原创 2019-01-05 00:28:24 · 345 阅读 · 0 评论