LeetCode解题报告汇总! All in One!

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/fuxuemingzhu/article/details/85112591

作者: 负雪明烛
id: fuxuemingzhu
个人博客: http://fuxuemingzhu.cn/


把自己刷过的所有题目做一个整理,并且用简洁的语言概括了一下思路,汇总成了一个表格。

题目的排列顺序是按照先Easy再Medium再Hard排列的,暂时还没有把题目全部整理完成。后序我会把刷过的所有的题目都整理到这个文档里。

题目 难度 解法 题目地址
566. Reshape the Matrix Easy 变长数组,求余法,维护行列计算在新的数组中的位置 https://blog.csdn.net/fuxuemingzhu/article/details/83626519
897. Increasing Order Search Tree Easy 直接中序遍历的结果放到链表结尾 https://blog.csdn.net/fuxuemingzhu/article/details/82349263
771. Jewels and Stones Easy 字典统计次数 https://blog.csdn.net/fuxuemingzhu/article/details/79188903
929. Unique Email Addresses Easy 字符串+set统计个数 https://blog.csdn.net/fuxuemingzhu/article/details/83478570
709. To Lower Case Easy ASIIC码操作ord,chr https://blog.csdn.net/fuxuemingzhu/article/details/81015228
804. Unique Morse Code Words Easy 字典映射 + set统计个数 https://blog.csdn.net/fuxuemingzhu/article/details/79774003
905. Sort Array By Parity Easy 自定义sorted函数的cmp为数字mod 2 https://blog.csdn.net/fuxuemingzhu/article/details/82732066
461. Hamming Distance Easy 先异或 再数1的个数 https://blog.csdn.net/fuxuemingzhu/article/details/54138423
657. Robot Return to Origin Easy Counter统计,判断是否相等 https://blog.csdn.net/fuxuemingzhu/article/details/83663650
832. Flipping an Image Easy 直接计算新的数组的每个位置的值即可 https://blog.csdn.net/fuxuemingzhu/article/details/80471495
617. Merge Two Binary Trees Easy 树的递归操作 https://blog.csdn.net/fuxuemingzhu/article/details/79052953
28. Implement strStr() Easy 字符串遍历+切片是否相等的判断 https://blog.csdn.net/fuxuemingzhu/article/details/79254558
890. Find and Replace Pattern Easy 直接使用字典做映射 https://blog.csdn.net/fuxuemingzhu/article/details/82014687
814. Binary Tree Pruning Medium 二叉树的后序遍历 https://blog.csdn.net/fuxuemingzhu/article/details/79858752
561. Array Partition I Easy 排序+求和 https://blog.csdn.net/fuxuemingzhu/article/details/71412574
728. Self Dividing Numbers Easy 直接遍历区间的每个数字进行判断 https://blog.csdn.net/fuxuemingzhu/article/details/79053113
852. Peak Index in a Mountain Array Easy 二分查找的变种,使用Mid位置和左右位置比较 https://blog.csdn.net/fuxuemingzhu/article/details/80721162
922. Sort Array By Parity II Easy 分别求出奇偶数组然后拼接 https://blog.csdn.net/fuxuemingzhu/article/details/83045735
883. Projection Area of 3D Shapes Easy 分别计算三视图的面积即可 https://blog.csdn.net/fuxuemingzhu/article/details/81748335
908. Smallest Range I Easy 直接数学计算 https://blog.csdn.net/fuxuemingzhu/article/details/82824685
867. Transpose Matrix Easy 先构建数组再遍历实现翻转 https://blog.csdn.net/fuxuemingzhu/article/details/81015450
589. N-ary Tree Preorder Traversal Easy 多叉树的先序遍历,可以用递归和迭代 https://blog.csdn.net/fuxuemingzhu/article/details/81021950
590. N-ary Tree Postorder Traversal Easy 多叉树的后序遍历 https://blog.csdn.net/fuxuemingzhu/article/details/81017965
350. Intersection of Two Arrays II Easy 先排序然后用两个指针移动找出数组交集 https://blog.csdn.net/fuxuemingzhu/article/details/54341965
876. Middle of the Linked List Easy 快慢指针同时向链表后面移动 https://blog.csdn.net/fuxuemingzhu/article/details/81748484
700. Search in a Binary Search Tree Easy BST中节点的查找,递归 https://blog.csdn.net/fuxuemingzhu/article/details/81015754
933. Number of Recent Calls Easy 找出满足一定条件的区间长度,可以使用二分或者队列 https://blog.csdn.net/fuxuemingzhu/article/details/83714891
559. Maximum Depth of N-ary Tree Easy 求树的高度,可以使用BFS和DFS https://blog.csdn.net/fuxuemingzhu/article/details/81021864
557. Reverse Words in a String III Easy 字符串的单词分别翻转再拼接到一起就好了 https://blog.csdn.net/fuxuemingzhu/article/details/70141268
806. Number of Lines To Write String Easy 使用字典保存每个字符的长度,然后统计每行的长度是否超过100就好了 https://blog.csdn.net/fuxuemingzhu/article/details/79810381
344. Reverse String Easy 字符串翻转,[::-1 https://blog.csdn.net/fuxuemingzhu/article/details/51284382
811. Subdomain Visit Count Easy 字典保存每个子域名出现的次数即可 https://blog.csdn.net/fuxuemingzhu/article/details/79789925
476. Number Complement Easy 求数字的补数,方法是异或上与其二进制数字的长度相等的全1二进制数 https://blog.csdn.net/fuxuemingzhu/article/details/54562124
821. Shortest Distance to a Character Easy 过两遍数组,分别找出距离左边和右边的这个字符的最短距离 https://blog.csdn.net/fuxuemingzhu/article/details/80471765
500. Keyboard Row Easy 使用字典保存每行元素,然后看每个单词是不是只由一行元素组成 https://blog.csdn.net/fuxuemingzhu/article/details/68953517
893. Groups of Special-Equivalent Strings Easy 把奇偶位置都取出来,重新拼接成字符串作为指纹,看总的有多少种指纹 https://blog.csdn.net/fuxuemingzhu/article/details/82083609
872. Leaf-Similar Trees Easy 先序、中序、后序都能得到叶子序列 https://blog.csdn.net/fuxuemingzhu/article/details/81748617
884. Uncommon Words from Two Sentences Easy 使用字典统计每个单词出现的次数,然后看字典keys()的交集,然后在字典中看是不是只出现了一次 https://blog.csdn.net/fuxuemingzhu/article/details/81749170
766. Toeplitz Matrix Easy 判断每个斜线是否相等,方法是判断每个元素是否和其左上角元素相等 https://blog.csdn.net/fuxuemingzhu/article/details/79127213
463. Island Perimeter Easy 求小岛的周长。使用所有陆地个数×4-相交部分×2. https://blog.csdn.net/fuxuemingzhu/article/details/83868905
682. Baseball Game Easy 用一个栈进行模拟 https://blog.csdn.net/fuxuemingzhu/article/details/79183412
868. Binary Gap Easy 二进制表示中1的最大间距,保留上一个1的位置即可 https://blog.csdn.net/fuxuemingzhu/article/details/81079495
104. Maximum Depth of Binary Tree Easy 二叉树的高度,可以用DFS和BFS https://blog.csdn.net/fuxuemingzhu/article/details/48490829
136. Single Number Easy 所有的数字出现了两次,其中一个只出现了一次。找出这个数字的方法可以使用字典统计或者异或运算 https://blog.csdn.net/fuxuemingzhu/article/details/54173334
496. Next Greater Element I Easy 找出某个数字右边比他大的数字,直接遍历查找就好了 https://blog.csdn.net/fuxuemingzhu/article/details/79080337
637. Average of Levels in Binary Tree Easy 求每层的二叉树的均值,可以使用BFS和DFS https://blog.csdn.net/fuxuemingzhu/article/details/79088554
693. Binary Number with Alternating Bits Easy 判断数字的二进制表示是不是01交错的。直接遍历判断,或者位运算。 https://blog.csdn.net/fuxuemingzhu/article/details/79089937
762. Prime Number of Set Bits in Binary Representation Easy 判断二进制数字的1的个数是不是质数 https://blog.csdn.net/fuxuemingzhu/article/details/79089092
917. Reverse Only Letters Easy 只翻转字母其余字符不动,可以使用栈、双指针 https://blog.csdn.net/fuxuemingzhu/article/details/82956271
292. Nim Game Easy 判断输入数字是不是4的倍数即可 https://blog.csdn.net/fuxuemingzhu/article/details/51284421
824. Goat Latin Easy 字符串处理,简单 https://blog.csdn.net/fuxuemingzhu/article/details/80471925
892. Surface Area of 3D Shapes Easy 统计立方体个数,减去相交面积 https://blog.csdn.net/fuxuemingzhu/article/details/82083893
784. Letter Case Permutation Easy 经典回溯法,把字符的大小写分别拼接到字符串尾部 https://blog.csdn.net/fuxuemingzhu/article/details/79360330
258. Add Digits Easy 两重循环,一直对每位数字求和直到剩余个位数 https://blog.csdn.net/fuxuemingzhu/article/details/49161129
283. Move Zeroes Easy 使用一个指针指向第一个为0的位置,然后遍历不是0的位置进行交换 https://blog.csdn.net/fuxuemingzhu/article/details/51284981
748. Shortest Completing Word Easy 找出符合某个模式的字符串,直接处理就好了 https://blog.csdn.net/fuxuemingzhu/article/details/79432228
690. Employee Importance Easy dfs https://blog.csdn.net/fuxuemingzhu/article/details/79091343
389. Find the Difference Easy 找多出来的字符,可以使用字典,也可以使用异或 https://blog.csdn.net/fuxuemingzhu/article/details/54174443
520. Detect Capital Easy 统计大写字符的个数,判断是不是在首位 https://blog.csdn.net/fuxuemingzhu/article/details/68957658
448. Find All Numbers Disappeared in an Array Easy 用set去重,找出没有出现的数字即可 https://blog.csdn.net/fuxuemingzhu/article/details/53981307
696. Count Binary Substrings Easy 先找出连续的0,1个数,然后进行交错求最小值,在求和 https://blog.csdn.net/fuxuemingzhu/article/details/79183556
454. 4Sum II Easy 4sum,先确定两个数字,然后看剩余两个数字的和是否出现过 https://blog.csdn.net/fuxuemingzhu/article/details/79473739
788. Rotated Digits Easy 字典保存翻转后的数字,判断是否相等即可。 https://blog.csdn.net/fuxuemingzhu/article/details/79378135
653. Two Sum IV - Input is a BST Easy BFS或者DFS,在遍历的过程中进行破案吨 https://blog.csdn.net/fuxuemingzhu/article/details/79120732
371. Sum of Two Integers Easy 位运算 https://blog.csdn.net/fuxuemingzhu/article/details/79379939
349. Intersection of Two Arrays Easy 用两个set求交集,然后转成List即可 https://blog.csdn.net/fuxuemingzhu/article/details/54236183
606. Construct String from Binary Tree Easy 先序遍历,可以省略右子树,所以需要做一个节点是否存在的判断 https://blog.csdn.net/fuxuemingzhu/article/details/79121550
206. Reverse Linked List Easy 翻转单链表,可以使用递归和迭代 https://blog.csdn.net/fuxuemingzhu/article/details/51290121
169. Majority Element Easy Moore投票法,或者字典统计次数 https://blog.csdn.net/fuxuemingzhu/article/details/51288749
171. Excel Sheet Column Number Easy 26进制,没有难度 https://blog.csdn.net/fuxuemingzhu/article/details/51286467
13. Roman to Integer Easy 使用字典保存映射,遍历求值就好了。 https://blog.csdn.net/fuxuemingzhu/article/details/48208995
937. Reorder Log Files Easy 分割排序,再拼接 https://blog.csdn.net/fuxuemingzhu/article/details/83961188
121. Best Time to Buy and Sell Stock Easy 一次遍历,如果后一天比前一天大就买了卖 https://blog.csdn.net/fuxuemingzhu/article/details/51291151
242. Valid Anagram Easy 判断字符串是否是同构的,直接统计词频或者排序 https://blog.csdn.net/fuxuemingzhu/article/details/51286195
860. Lemonade Change Easy 贪心算法,找零钱先找大的面额,如果不够再用小的面额 https://blog.csdn.net/fuxuemingzhu/article/details/80913955
217. Contains Duplicate Easy 判断数组是否有重复,可以统计词频,判断set长度是否相等,排序等方法 https://blog.csdn.net/fuxuemingzhu/article/details/51289768
427. Construct Quad Tree Easy 建立四叉树,使用递归,判断4个叶子全部是0或者1 https://blog.csdn.net/fuxuemingzhu/article/details/81836838
706. Design HashMap Easy 设计一个字典,直接开个很大的数组即可,内存放得下 https://blog.csdn.net/fuxuemingzhu/article/details/81017297
538. Convert BST to Greater Tree Easy 把每个节点变成比它大的节点的值的和,采用逆中序遍历。 https://blog.csdn.net/fuxuemingzhu/article/details/79132336
100. Same Tree Easy 判断两棵数是否相等,直接递归 https://blog.csdn.net/fuxuemingzhu/article/details/51285076
530. Minimum Absolute Difference in BST Easy 中序遍历,保存前一个节点,当前节点的值减去前一个节点的值 https://blog.csdn.net/fuxuemingzhu/article/details/69666671
783. Minimum Distance Between BST Nodes Easy 和上题完全一样 https://blog.csdn.net/fuxuemingzhu/article/details/79402127
383. Ransom Note Easy 使用字典统计每个字符出现的次数,前者小于后者即可 https://blog.csdn.net/fuxuemingzhu/article/details/54178342
796. Rotate String Easy 字符串切片 https://blog.csdn.net/fuxuemingzhu/article/details/79521194
717. 1-bit and 2-bit Characters Easy 单次遍历,判断前面满足的条件下,最后一位是0即可。 https://blog.csdn.net/fuxuemingzhu/article/details/79130681
453. Minimum Moves to Equal Array Elements Easy 把n-1个数字加1,相等于把最大值-1.求和-n*最小值 https://blog.csdn.net/fuxuemingzhu/article/details/54177981
733. Flood Fill Easy 对相同颜色进行染色,可以使用DFS和BFS. https://blog.csdn.net/fuxuemingzhu/article/details/79401716
404. Sum of Left Leaves Easy 求所有左叶子的和,要判断是不是在左边,判断是不是叶子,然后加到结果中 https://blog.csdn.net/fuxuemingzhu/article/details/54178595
447. Number of Boomerangs Easy 统计回旋镖的个数,不能暴力解决,需要使用排列组合公式n*(n-1) https://blog.csdn.net/fuxuemingzhu/article/details/54379349
598. Range Addition II Easy 求队列的最小值即可 https://blog.csdn.net/fuxuemingzhu/article/details/79398272
492. Construct the Rectangle Easy 从算术平方根开始找约数即可 https://blog.csdn.net/fuxuemingzhu/article/details/68957959
167. Two Sum II - Input array is sorted Easy 前后指针同时向中间走,找到target之后停止 https://blog.csdn.net/fuxuemingzhu/article/details/70232518
387. First Unique Character in a String Easy 首先做个字符出现次数的统计,然后再次遍历,找出只出现了一次的第一个字符。 https://blog.csdn.net/fuxuemingzhu/article/details/84139374
697. Degree of an Array Easy 求最大的出现次数的所有数字,其最左右出现的位置差的最小值 https://blog.csdn.net/fuxuemingzhu/article/details/79146067
455. Assign Cookies Easy 贪心算法,尽可能给小孩满足其欲望的饼干 https://blog.csdn.net/fuxuemingzhu/article/details/54177627
108. Convert Sorted Array to Binary Search Tree Easy 构建BST,使用中间数进行分割,用递归 https://blog.csdn.net/fuxuemingzhu/article/details/70665213
506. Relative Ranks Easy 相对排名,可以使用堆或者排序或者argsort https://blog.csdn.net/fuxuemingzhu/article/details/70173434
661. Image Smoother Easy 直接暴力求平均即可 https://blog.csdn.net/fuxuemingzhu/article/details/79156499
409. Longest Palindrome Easy 统计出现次数的奇偶就可以 https://blog.csdn.net/fuxuemingzhu/article/details/54236594
599. Minimum Index Sum of Two Lists Easy 保存出现的索引和与元素的对应,使用堆保存最小的就行 https://blog.csdn.net/fuxuemingzhu/article/details/79138621
268. Missing Number Easy 理论和-当前和 https://blog.csdn.net/fuxuemingzhu/article/details/70332471
563. Binary Tree Tilt Easy 后序遍历函数返回的是左右子树的差,在里面用变量求和 https://blog.csdn.net/fuxuemingzhu/article/details/71440281
830. Positions of Large Groups Easy 找到长度大于3的连续字符,需要判断结束!! https://blog.csdn.net/fuxuemingzhu/article/details/80472242
350. Intersection of Two Arrays II Easy 可以排序,也可以使用字典统计次数 https://blog.csdn.net/fuxuemingzhu/article/details/54341965
543. Diameter of Binary Tree Easy 递归求树的深度,同时求左右两个深度的和的最大值 https://blog.csdn.net/fuxuemingzhu/article/details/70338312
551. Student Attendance Record I Easy 统计A的个数,并且判断连续L的个数 https://blog.csdn.net/fuxuemingzhu/article/details/70337973
121. Best Time to Buy and Sell Stock Easy 保存当前的最小值以及最大收益即可 https://blog.csdn.net/fuxuemingzhu/article/details/51291151
628. Maximum Product of Three Numbers Easy 找出三个数最大的乘积 https://blog.csdn.net/fuxuemingzhu/article/details/79169635
401. Binary Watch Easy 使用combinations函数 https://blog.csdn.net/fuxuemingzhu/article/details/54344098
746. Min Cost Climbing Stairs Easy 动态规划 https://blog.csdn.net/fuxuemingzhu/article/details/79188612
925. Long Pressed Name Easy 使用双指针,统计连续字符出现的次数 https://blog.csdn.net/fuxuemingzhu/article/details/83245395
541. Reverse String II Easy Python的切片翻转 https://blog.csdn.net/fuxuemingzhu/article/details/70141909
705. Design HashSet Easy 直接开数组就行 https://blog.csdn.net/fuxuemingzhu/article/details/81016992
107. Binary Tree Level Order Traversal II Easy DFS和BFS都可以 https://blog.csdn.net/fuxuemingzhu/article/details/49108449
504. Base 7 Easy 转成7进制 https://blog.csdn.net/fuxuemingzhu/article/details/70194688
115. Distinct Subsequences Easy 动规,判断当前字符是否相等 https://blog.csdn.net/fuxuemingzhu/article/details/84228383
21. Merge Two Sorted Lists Easy 可以使用递归或者迭代 https://blog.csdn.net/fuxuemingzhu/article/details/51291406
458. Poor Pigs Easy 类似拨号键盘,多维空间求解 https://blog.csdn.net/fuxuemingzhu/article/details/81079261
257. Binary Tree Paths Easy 打印二叉树的路径,使用递归和迭代 https://blog.csdn.net/fuxuemingzhu/article/details/71249429
844. Backspace String Compare Easy 字符串可以退格,使用栈轻松解决 https://blog.csdn.net/fuxuemingzhu/article/details/80643408
202. Happy Number Easy 递归和迭代两种做法 https://blog.csdn.net/fuxuemingzhu/article/details/49180507
674. Longest Continuous Increasing Subsequence Easy 简单的动态规划 https://blog.csdn.net/fuxuemingzhu/article/details/79220527
744. Find Smallest Letter Greater Than Target Easy 线性扫描或者二分 https://blog.csdn.net/fuxuemingzhu/article/details/79137225
118. Pascal’s Triangle Easy 提前构造出来,然后处理每行即可 https://blog.csdn.net/fuxuemingzhu/article/details/51346488
671. Second Minimum Node In a Binary Tree Easy 递归的时候找第二小值 https://blog.csdn.net/fuxuemingzhu/article/details/79222455
720. Longest Word in Dictionary Easy 先排序,再找前缀是否存在。 https://blog.csdn.net/fuxuemingzhu/article/details/79123277
27. Remove Element Easy 使用双指针或者标记指针使得前面都是满足要求的,后面都不满足 https://blog.csdn.net/fuxuemingzhu/article/details/51303161
70. Climbing Stairs Easy 动态规划 https://blog.csdn.net/fuxuemingzhu/article/details/51290778
415. Add Strings Easy 直接模拟大整数加法,需要注意进位问题 https://blog.csdn.net/fuxuemingzhu/article/details/54380737
235. Lowest Common Ancestor of a Binary Search Tree Easy BST找公共祖先,使用递归很简单 https://blog.csdn.net/fuxuemingzhu/article/details/51290289
594. Longest Harmonious Subsequence Easy 统计相邻的数字是否都存在即可 https://blog.csdn.net/fuxuemingzhu/article/details/79233752
101. Symmetric Tree Easy 可以使用BFS和DFS两种方法 https://blog.csdn.net/fuxuemingzhu/article/details/51345707
53. Maximum Subarray Easy 动态规划找子数组最大和 https://blog.csdn.net/fuxuemingzhu/article/details/71101802
819. Most Common Word Easy 正则+统计 https://blog.csdn.net/fuxuemingzhu/article/details/80472079
231. Power of Two Easy 判断二进制是不是只有1个1即可 https://blog.csdn.net/fuxuemingzhu/article/details/51290981
405. Convert a Number to Hexadecimal Easy 转成16进制,难点在于负数的处理:加上1<<32 https://blog.csdn.net/fuxuemingzhu/article/details/54426643
83. Remove Duplicates from Sorted List Easy 递归和循环 https://blog.csdn.net/fuxuemingzhu/article/details/51290506
326. Power of Three Easy 循环和迭代 https://blog.csdn.net/fuxuemingzhu/article/details/51290895
191. Number of 1 Bits Easy 使用位移统计二进制个数 https://blog.csdn.net/fuxuemingzhu/article/details/51290376
437. Path Sum III Easy 找路径的个数,使用DFS*2或者BFS+DFS https://blog.csdn.net/fuxuemingzhu/article/details/71097135
704. Binary Search Easy 二分的模板 https://blog.csdn.net/fuxuemingzhu/article/details/81017415
119. Pascal’s Triangle II Easy 原地翻转可以用倒序遍历 https://blog.csdn.net/fuxuemingzhu/article/details/51348629
232. Implement Queue using Stacks Easy 两个栈实现一个队列 https://blog.csdn.net/fuxuemingzhu/article/details/51345762
572. Subtree of Another Tree Easy DFS*2或DFS+BSF https://blog.csdn.net/fuxuemingzhu/article/details/71440802
198. House Robber Easy 简单dp,当前房间偷和不偷两种状态 https://blog.csdn.net/fuxuemingzhu/article/details/51291936
703. Kth Largest Element in a Stream Easy 使用小根堆维护k个值,则第一个元素就是第k大元素 https://blog.csdn.net/fuxuemingzhu/article/details/81027116
345. Reverse Vowels of a String Easy 使用栈进行翻转,或者使用双指针 https://blog.csdn.net/fuxuemingzhu/article/details/51291677
66. Plus One Easy 使用carry表示进位 https://blog.csdn.net/fuxuemingzhu/article/details/51346096
263. Ugly Number Easy 除去2,3,5因子即可 https://blog.csdn.net/fuxuemingzhu/article/details/49183961
35. Search Insert Position Easy 二分查找 https://blog.csdn.net/fuxuemingzhu/article/details/70738108
645. Set Mismatch Easy 使用统计次数或者直接求和计算 https://blog.csdn.net/fuxuemingzhu/article/details/79247916
747. Largest Number At Least Twice of Others Easy 找出最大值,然后弹掉,再找次大值即可。 https://blog.csdn.net/fuxuemingzhu/article/details/79188909
342. Power of Four Easy 递归和迭代 https://blog.csdn.net/fuxuemingzhu/article/details/51291091
724. Find Pivot Index Easy 先求和,在遍历求前半部分的和,找出左边等于右边 https://blog.csdn.net/fuxuemingzhu/article/details/79248308
9. Palindrome Number Easy 可以先翻转成整数,然后判断和原来的是否相等 https://blog.csdn.net/fuxuemingzhu/article/details/71334663
482. License Key Formatting Easy 计算第一个分割的长度,后面都是等长的了 https://blog.csdn.net/fuxuemingzhu/article/details/79234075
1. Two Sum Easy 保存已经出现过的数字的索引,当下次遍历的时候遇到了满足要求的结果,那么既是停止 https://blog.csdn.net/fuxuemingzhu/article/details/72465759
459. Repeated Substring Pattern Easy 判断每个子串重复多次能不能组成原来的串即可 https://blog.csdn.net/fuxuemingzhu/article/details/54564801
849. Maximize Distance to Closest Person Easy 从前向后以及从后向前遍历两次,取最近距离 https://blog.csdn.net/fuxuemingzhu/article/details/80643250
38. Count and Say Easy 统计字符连续出现的次数,并说出来,需要注意最后的一个字符也要添加上去 https://blog.csdn.net/fuxuemingzhu/article/details/71618640
80. Remove Duplicates from Sorted Array II Easy 快指针移动判断和慢指针是否相等,如果不等就换到前面来 https://blog.csdn.net/fuxuemingzhu/article/details/82829709
643. Maximum Average Subarray I Easy 一定注意是长度为k的滑动窗口,注意下标 https://blog.csdn.net/fuxuemingzhu/article/details/79248629
501. Find Mode in Binary Search Tree Easy 如果使用附加空间,可以使用字典保存次数;否则需要遍历两次,判断出现次数。 https://blog.csdn.net/fuxuemingzhu/article/details/71124600
374. Guess Number Higher or Lower Easy 使用二分查找 https://blog.csdn.net/fuxuemingzhu/article/details/71516105
743. Network Delay Time Easy dijkstra算法 https://leetcode.com/problems/network-delay-time/description/
558. Quad Tree Intersection Easy 递归构造 https://blog.csdn.net/fuxuemingzhu/article/details/82356008
172. Factorial Trailing Zeroes Easy 数有多少个5就行了 https://blog.csdn.net/fuxuemingzhu/article/details/51347044
441. Arranging Coins Easy 二分查找满足条件的层数即可 https://blog.csdn.net/fuxuemingzhu/article/details/71330733
225. Implement Stack using Queues Easy 使用一个队列就能实现栈,每次Push的时候,把队列里的所有元素弹出再放进来就好了。 https://blog.csdn.net/fuxuemingzhu/article/details/72598111
67. Add Binary Easy 使用进位进行模拟 ddhttps://blog.csdn.net/fuxuemingzhu/article/details/77341154v
434. Number of Segments in a String Easy string.split()默认就是按照多个空格分割 https://blog.csdn.net/fuxuemingzhu/article/details/71194298
112. Path Sum Easy 递归和迭代都能满足 https://blog.csdn.net/fuxuemingzhu/article/details/71715810
205. Isomorphic Strings Easy 分别看s到t的映射和t到s的映射是不是一一映射的 https://blog.csdn.net/fuxuemingzhu/article/details/72127108
443. String Compression Easy 使用Pos变量维护应该放到哪个位置,然后一次遍历统计次数就好了 https://blog.csdn.net/fuxuemingzhu/article/details/79183289
303. Range Sum Query - Immutable Easy 保存每个位置的累积和 https://blog.csdn.net/fuxuemingzhu/article/details/79253036
438. Find All Anagrams in a String Easy 滑动窗口,保存等长的子字符串中包含的字符数是否和另外一个相等 https://blog.csdn.net/fuxuemingzhu/article/details/79184109
20. Valid Parentheses Easy 使用栈判断括号是否合法 https://blog.csdn.net/fuxuemingzhu/article/details/72366868
840. Magic Squares In Grid Easy 暴力判断每个9*9的格子是不是满足题意的河图 https://blog.csdn.net/fuxuemingzhu/article/details/80473253
141. Linked List Cycle Easy 走两步走一步,看是否重合 https://blog.csdn.net/fuxuemingzhu/article/details/51297249
203. Remove Linked List Elements Easy 递归解法不好想,但是代码很简单 https://blog.csdn.net/fuxuemingzhu/article/details/77340945
234. Palindrome Linked List Easy 利用一个数组保存所有的数字,然后判断数组是不是回文的。 https://blog.csdn.net/fuxuemingzhu/article/details/72597942
111. Minimum Depth of Binary Tree Easy DFS/BFS,其实DFS更难 https://blog.csdn.net/fuxuemingzhu/article/details/48519035
290. Word Pattern Easy 一一映射 https://blog.csdn.net/fuxuemingzhu/article/details/72528424
155. Min Stack Easy 使用辅助栈保存最小值 https://blog.csdn.net/fuxuemingzhu/article/details/79253237
219. Contains Duplicate II Easy 使用字典保存出现的位置,当新的元素到来的时候,更新字典 https://blog.csdn.net/fuxuemingzhu/article/details/77387169
941. Valid Mountain Array Easy 两个while就可以了 https://blog.csdn.net/fuxuemingzhu/article/details/84206380
88. Merge Sorted Array Easy 从后向前进行遍历,每次找到大的往后移动 https://blog.csdn.net/fuxuemingzhu/article/details/77444695
914. X of a Kind in a Deck of Cards Easy 需要进行一个遍历,找到是否存在这个分组大小 https://blog.csdn.net/fuxuemingzhu/article/details/82914279
680. Valid Palindrome II Easy 需要用到双指针,先找到第一个不相等的位置,然后去除左边或者右边,判断是否是回文 https://blog.csdn.net/fuxuemingzhu/article/details/79252779
687. Longest Univalue Path Easy 定义的DFS是对过root的单臂进行循环,但是更新的结果是双臂,有点意思 https://blog.csdn.net/fuxuemingzhu/article/details/79248926
14. Longest Common Prefix Easy 遍历最短的子串的每一位,看所有字符串在这一位上是不是相等的 https://blog.csdn.net/fuxuemingzhu/article/details/77561186
686. Repeated String Match Easy 重复NB/NA + 3次,看b是不是在a里 https://blog.csdn.net/fuxuemingzhu/article/details/79574835
122.Best Time to Buy and Sell Stock II Easy 只要每天的比前面一天高,那么就买上并且卖掉即可 https://blog.csdn.net/fuxuemingzhu/article/details/70258549
28. Implement strStr() Easy 循环加切片 https://blog.csdn.net/fuxuemingzhu/article/details/79254558
475. Heaters Easy 找出最临近的距离 https://blog.csdn.net/fuxuemingzhu/article/details/79254295
754. Reach a Number Easy 数学题,非常不喜欢 https://blog.csdn.net/fuxuemingzhu/article/details/84556932
400. Nth Digit Easy 数学计算第多少位 https://blog.csdn.net/fuxuemingzhu/article/details/84559975
69. Sqrt(x) Easy 二分查找或者牛顿法 https://blog.csdn.net/fuxuemingzhu/article/details/79254648
581. Shortest Unsorted Continuous Subarray Easy 先排序,然后比较不等的位置 https://blog.csdn.net/fuxuemingzhu/article/details/79254454
190. Reverse Bits Easy 翻转二进制再转成整数 https://blog.csdn.net/fuxuemingzhu/article/details/79254344
125. Valid Palindrome Easy 过滤掉不是字母的字符,然后判断是不是回文即可 https://blog.csdn.net/fuxuemingzhu/article/details/79252936
874. Walking Robot Simulation Easy 模拟整个过程即可 https://blog.csdn.net/fuxuemingzhu/article/details/82356556
532. K-diff Pairs in an Array Easy 找绝对值出现等于k的次数,需要对k进行判断 https://blog.csdn.net/fuxuemingzhu/article/details/79255633
168. Excel Sheet Column Title Easy 需要对26取余,并且做个判断,因为0\26对26取余的结果是一样的 https://blog.csdn.net/fuxuemingzhu/article/details/51286857
189. Rotate Array Easy 可以使用额外数组,也可使用递归原地翻转 https://blog.csdn.net/fuxuemingzhu/article/details/79258753
665. Non-decreasing Array Easy 找到变小的位置,然后和再前面的数字进行判断,看是应该修改当前的还是前面的 https://blog.csdn.net/fuxuemingzhu/article/details/79264475
707. Design Linked List Easy 自己实现链表,挺复杂的。可以使用list进行模拟,方便很多。 https://blog.csdn.net/fuxuemingzhu/article/details/81026066
938. Range Sum of BST Medium 需要根据根节点的值进行判断,邮编和左边需不需要继续寻找 https://blog.csdn.net/fuxuemingzhu/article/details/83961263
807. Max Increase to Keep City Skyline Medium 分别找出行和咧的最大值,把每个位置增长到行列最大值的最小值 https://blog.csdn.net/fuxuemingzhu/article/details/79820383
535. Encode and Decode TinyURL Medium 使用字典完成映射 https://blog.csdn.net/fuxuemingzhu
654. Maximum Binary Tree Medium 找到最大值,然后数组切片 https://blog.csdn.net/fuxuemingzhu/article/details/79265180
701. Insert into a Binary Search Tree Medium 递归解法,直接对当前节点进行操作! https://blog.csdn.net/fuxuemingzhu/article/details/82385503
890. Find and Replace Pattern Medium 判断是不是一一映射 https://blog.csdn.net/fuxuemingzhu/article/details/82014687
921. Minimum Add to Make Parentheses Valid Medium 使用一个栈 https://blog.csdn.net/fuxuemingzhu/article/details/83045871
797. All Paths From Source to Target Medium 回溯法找路径 https://blog.csdn.net/fuxuemingzhu/article/details/79624149
861. Score After Flipping Matrix Medium 把行进行翻转,按列统计1的个数即可 https://blog.csdn.net/fuxuemingzhu/article/details/81118328
894. All Possible Full Binary Trees Medium 使用两种循环遍历可能构成的左子树和右子树,每次构建新的root https://blog.csdn.net/fuxuemingzhu/article/details/82084204
763. Partition Labels Medium 使用字典保存每个字符最后出现的位置,如果一个区间内字符的最后位置的都在一起,那么就添加到结果里 https://blog.csdn.net/fuxuemingzhu/article/details/79265829
419. Battleships in a Board Medium 直接数有多少小岛就行,判断小岛可以使用它的最左上角元素即可 https://blog.csdn.net/fuxuemingzhu/article/details/79403172
537. Complex Number Multiplication Medium 复数运算,重点是分割字符串 https://blog.csdn.net/fuxuemingzhu/article/details/79266080
338. Counting Bits Medium i的二进制1个数等于i/2的二进制个数+i%2 https://blog.csdn.net/fuxuemingzhu/article/details/70806676
885. Spiral Matrix III Medium 保留循环更新步数,很恶心 https://blog.csdn.net/fuxuemingzhu/article/details/82389223
791. Custom Sort String Medium 统计次数,拼接成字符串 https://blog.csdn.net/fuxuemingzhu/article/details/79378688
442. Find All Duplicates in an Array Medium 原地变成负数,如果已经是负数,那么说明出现了两次。 https://blog.csdn.net/fuxuemingzhu/article/details/79275549
355. Design Twitter Medium 使用优先级队列弹出最新的内容 https://blog.csdn.net/fuxuemingzhu/article/details/82155420
841. Keys and Rooms Medium 可以使用DFS和BFS解决 https://blog.csdn.net/fuxuemingzhu/article/details/80476862
406. Queue Reconstruction by Height Medium 先插入长得高的他们不会影响别人,然后在对应位置插入次高的 https://blog.csdn.net/fuxuemingzhu/article/details/68486884
513. Find Bottom Left Tree Value Medium 层次遍历,找出最后一层的第一个节点即可 https://blog.csdn.net/fuxuemingzhu/article/details/70161829
739. Daily Temperatures Medium 使用一个栈,保存每个元素,如果后面的元素比较大,那么就已知出栈操作 https://blog.csdn.net/fuxuemingzhu/article/details/79285081
946. Validate Stack Sequences Medium 使用栈进行模拟,无论如何都把当前的元素弹出,然后和弹出的元素进行比较,相等的话一直弹出 https://blog.csdn.net/fuxuemingzhu/article/details/84495797
515. Find Largest Value in Each Tree Row Medium 遍历每一层,找出最大值即可。 https://blog.csdn.net/fuxuemingzhu/article/details/70183314
540. Single Element in a Sorted Array Medium 可以使用很风骚的二分查找k, https://blog.csdn.net/fuxuemingzhu/article/details/79275636
889. Construct Binary Tree from Preorder and Postorder Traversal Medium 找到后序的倒数第二个元素就是右子树的根节点 https://blog.csdn.net/fuxuemingzhu/article/details/82391321
260. Single Number III Medium 使用异或或者字典解决 https://blog.csdn.net/fuxuemingzhu/article/details/79434100
553. Optimal Division Medium 这个题非常tricky,没意思 https://blog.csdn.net/fuxuemingzhu/article/details/79403723
647. Palindromic Substrings Medium 判断回文,需要判断去掉两头字符之后是否仍然是回文,动态规划 https://blog.csdn.net/fuxuemingzhu/article/details/79433960
695. Max Area of Island Medium 找到岛的数量,这个题可以使用BFS或者DFS的方法 https://blog.csdn.net/fuxuemingzhu/article/details/79182435
856. Score of Parentheses Medium 可以使用栈和递归,这个题很巧妙,是个不错的题目 https://blog.csdn.net/fuxuemingzhu/article/details/84956643
919. Complete Binary Tree Inserter Medium 使用数组保存每个节点的指针,因为是完全二叉树,所以节点位置除以2就得到了它的父亲节点 https://blog.csdn.net/fuxuemingzhu/article/details/82958284
451. Sort Characters By Frequency Medium 根据出现次数排序,然后构建新的字符串即可 https://blog.csdn.net/fuxuemingzhu/article/details/79437548
789. Escape The Ghosts Medium 找出是否存在更小的曼哈顿距离 https://blog.csdn.net/fuxuemingzhu/article/details/80480462
94. Binary Tree Inorder Traversal Medium 中序遍历本身很简单,但是这个递归的写法不好想 https://blog.csdn.net/fuxuemingzhu/article/details/79294461
865. Smallest Subtree with all the Deepest Nodes Medium 定义递归函数:返回<最大深度,最大深度对应的节点> https://blog.csdn.net/fuxuemingzhu/article/details/82432130
508. Most Frequent Subtree Sum Medium 遍历求和,字典统计出现次数最多的所有元素 http://www.cnblogs.com/grandyang/p/6481682.html
526. Beautiful Arrangement Medium 经典回溯法,要背会 https://blog.csdn.net/fuxuemingzhu/article/details/79431941
238. Product of Array Except Self Medium 使用两次遍历,分别从左边和右边向中间靠拢 https://blog.csdn.net/fuxuemingzhu/article/details/79325534
712. Minimum ASCII Delete Sum for Two Strings Medium 和LCS很接近的DP题目 https://blog.csdn.net/fuxuemingzhu/article/details/79822689
817. Linked List Components Medium 判断当前节点在set中,但是下一个节点不在即可 https://blog.csdn.net/fuxuemingzhu/article/details/80479431
347. Top K Frequent Elements Medium 使用字典统计次数,使用优先级队列实现排序 https://blog.csdn.net/fuxuemingzhu/article/details/79294073
462. Minimum Moves to Equal Array Elements II Medium 找出中位数,然后求所有数字到中位数的距离和 https://blog.csdn.net/fuxuemingzhu/article/details/79437926
46. Permutations Medium 经典回溯法 https://blog.csdn.net/fuxuemingzhu/article/details/79363903
495. Teemo Attacking Medium 计算每次中毒的开始和结束时间 https://blog.csdn.net/fuxuemingzhu/article/details/79438658
22. Generate Parentheses Medium 经典回溯法 https://blog.csdn.net/fuxuemingzhu/article/details/79362373
529. Minesweeper Medium 扫雷游戏,使用DFS https://blog.csdn.net/fuxuemingzhu/article/details/79462285
667. Beautiful Arrangement II Medium 每次把后面最大数字放到前面来就能增加一种新的差值 https://blog.csdn.net/fuxuemingzhu/article/details/79437401
677. Map Sum Pairs Medium 前缀树的题目,可以背一背 https://blog.csdn.net/fuxuemingzhu/article/details/79436619
547. Friend Circles Medium 并查集的题目 https://blog.csdn.net/fuxuemingzhu/article/details/70258103
565. Array Nesting Medium 一直遍历就好了,使用一个visited数组,但不是回溯。 https://blog.csdn.net/fuxuemingzhu/article/details/79460546
947. Most Stones Removed with Same Row or Column Medium 需要使用并查集,非常考验抽象能力 https://blog.csdn.net/fuxuemingzhu/article/details/84500642
858. Mirror Reflection Medium 镜像反射,需要找规律,分偶数和奇数进行讨论 https://blog.csdn.net/fuxuemingzhu/article/details/82432579
676. Implement Magic Dictionary Medium 找到存不存在汉明间距是1 https://blog.csdn.net/fuxuemingzhu/article/details/79447934
781. Rabbits in Forest Medium 对兔子出现次数进行统计,然后求一个公式。 https://blog.csdn.net/fuxuemingzhu/article/details/79457764
769. Max Chunks To Make Sorted Medium 从左到右遍历一次,时刻保持当前的最大值,如果当前最大值等于索引,那么chunck+1. https://blog.csdn.net/fuxuemingzhu/article/details/80482014
655. Print Binary Tree Medium 先把二叉树构造出来,然后使用类似二分查找左右分治的方法。 https://blog.csdn.net/fuxuemingzhu/article/details/79439026
208. Implement Trie (Prefix Tree) Medium 构造字典树,是个好题,需要背会 https://blog.csdn.net/fuxuemingzhu/article/details/79388432
648. Replace Words Medium 使用字典树或者拉链法求解 https://blog.csdn.net/fuxuemingzhu/article/details/79391682
421. Maximum XOR of Two Numbers in an Array Medium 暴力求解会超时,需要使用异或的性质从最高位开始遍历。或者使用字典树。 https://blog.csdn.net/fuxuemingzhu/article/details/79473171
40. Combination Sum II Medium 经典的回溯法,这个题需要背会 https://blog.csdn.net/fuxuemingzhu/article/details/79343638

猜你喜欢

转载自blog.csdn.net/fuxuemingzhu/article/details/85112591
今日推荐