leetcode题解汇总

2016年6月-9月期间,共计刷题204题,大部分都有做记录,现按照题目类型进行划分,重刷一遍,一则加深印象,二则方便日后阅读。

链表

1、反转单向链表

http://blog.csdn.net/sysu_cis/article/details/51705591#t2

2、反转单向链表II

http://blog.csdn.net/sysu_cis/article/details/52136680#t4


3、回文链表

http://blog.csdn.net/sysu_cis/article/details/51775299#t3

4、有序链表删除重复元素

http://blog.csdn.net/sysu_cis/article/details/51723219

5、有序链表删除重复元素II

http://blog.csdn.net/sysu_cis/article/details/52170574#t3

6、删除链表中指定值元素

http://blog.csdn.net/sysu_cis/article/details/51775299#t2

7、删除链表倒数第N个元素

http://blog.csdn.net/sysu_cis/article/details/51762428#t3

8、合并两个有序链表

http://blog.csdn.net/sysu_cis/article/details/51708095


9、链表排序                                                                                    归并排序

http://blog.csdn.net/sysu_cis/article/details/52012006#t4

10、链表插入排序

http://blog.csdn.net/sysu_cis/article/details/52012006#t3

11、成对交换链表元素

http://blog.csdn.net/sysu_cis/article/details/51723222


12、判断有环链表

http://blog.csdn.net/sysu_cis/article/details/51708095#t2

13、判断有环链表II                (找到入口位置)

http://blog.csdn.net/sysu_cis/article/details/51975680#t4


14、两个链表的交点

http://blog.csdn.net/sysu_cis/article/details/51757743#t5

15、两个链表的加法

http://blog.csdn.net/sysu_cis/article/details/52374344#t3


16、奇偶链表        (奇数位置放前面,偶数位置放后面)

http://blog.csdn.net/sysu_cis/article/details/51837988#t3

17、划分链表            (小于x放前面,大于等于x放后面,保持原有顺序)

http://blog.csdn.net/sysu_cis/article/details/52016914#t2

18、将一个有序链表转换为BST

http://blog.csdn.net/sysu_cis/article/details/52000291#t4


数组

1、在一个整型数组中查找是否含有重复元素。

http://blog.csdn.net/sysu_cis/article/details/51705591#t0

2、在一个整型数组中查找是否含有重复元素II  (|i-j|<=k)

http://blog.csdn.net/sysu_cis/article/details/51762428#t1

3、在一个整型数组中查找是否含有重复元素III(|nums[i]-nums[j]|<=t,|i-j|<=k)

http://blog.csdn.net/sysu_cis/article/details/52333598#t2


4、两个数组的交集(多次重复只算一次)

http://blog.csdn.net/sysu_cis/article/details/52333598#t3

5、两个数组的交集II(多次重复算多次)

http://blog.csdn.net/sysu_cis/article/details/51705591


6、合并两个有序数组

http://blog.csdn.net/sysu_cis/article/details/51762428#t2


7、排列颜色  (数组中有0、1、2三种,对其进行排序)

http://blog.csdn.net/sysu_cis/article/details/51901140#t6

8、数组除去自身元素的乘积

http://blog.csdn.net/sysu_cis/article/details/51814857#t4

9、有序数组删除重复元素

http://blog.csdn.net/sysu_cis/article/details/51738240

10、有序数组删除重复元素II

http://blog.csdn.net/sysu_cis/article/details/51934432#t3


11、删除元素    (返回删除指定元素,有多少删多少,剩下的元素个数并且剩下元素要在前面)

http://blog.csdn.net/sysu_cis/article/details/51730192#t3

12、杨辉三角        (生成杨辉三角的前n行)

http://blog.csdn.net/sysu_cis/article/details/51736673

13、杨辉三角II        (生成杨辉三角的第n行)

http://blog.csdn.net/sysu_cis/article/details/51738240


14、两数和        (找到和为定值的两数下标)

http://blog.csdn.net/sysu_cis/article/details/51779664#t5

15、两数和II--输入数组有序    

http://blog.csdn.net/sysu_cis/article/details/52402650#t2

16、三数和

http://blog.csdn.net/sysu_cis/article/details/52402650#t3

17、最接近的三数和

http://blog.csdn.net/sysu_cis/article/details/52031850#t3

18、四数和

http://blog.csdn.net/sysu_cis/article/details/52402650#t4


19、旋转数组        (求一个数组旋转n位之后的数组)

http://blog.csdn.net/sysu_cis/article/details/51812720#t1

20、数组中的前k频率的元素

http://blog.csdn.net/sysu_cis/article/details/51822901#t2


21、旋转矩阵        (给定一个m*n矩阵,按照顺时针去访问)

http://blog.csdn.net/sysu_cis/article/details/51879907#t4

22、旋转矩阵II    (生成1到n平方的数字,即矩阵是方形的,按照顺时针存入)

http://blog.csdn.net/sysu_cis/article/details/51879907#t5


23、旋转图像

http://blog.csdn.net/sysu_cis/article/details/51901140#t5

24、游戏人生

http://blog.csdn.net/sysu_cis/article/details/51921252#t3

25、装最多的水                                                                                两指针

http://blog.csdn.net/sysu_cis/article/details/51913445#t2


26、一个数组中第K大的数                                                            快排、堆排

http://blog.csdn.net/sysu_cis/article/details/51913445#t3

27、两个有序数组中找到K对最小和

http://blog.csdn.net/sysu_cis/article/details/52564096#t4

28、设置矩阵中的0            (将原本的0所处行列全部设置为0)

http://blog.csdn.net/sysu_cis/article/details/51913445#t4


29、岛的数量    

http://blog.csdn.net/sysu_cis/article/details/52050072#t4


1、BST的LCA(最低公共祖先)

http://blog.csdn.net/sysu_cis/article/details/51705839

2、普通二叉树的LCA

http://blog.csdn.net/sysu_cis/article/details/52136680#t3


3、二叉树的层次遍历    (从上往下)

http://blog.csdn.net/sysu_cis/article/details/52136680

4、二叉树的层次遍历II    (从下往上)

http://blog.csdn.net/sysu_cis/article/details/51730192

5、二叉树zigzag层次遍历    (顺逆交替)

http://blog.csdn.net/sysu_cis/article/details/52016914



6、二叉树最小深度

http://blog.csdn.net/sysu_cis/article/details/51751141#t3


7、判断是否平衡二叉树                    (dfs写法还需要继续巩固)

http://blog.csdn.net/sysu_cis/article/details/51730192

8、判断二叉树路径和为sum的路径                                                        dfs

http://blog.csdn.net/sysu_cis/article/details/51751141#t1

9、二叉树所有路径和为sum的路径 II                                                        dfs        

http://blog.csdn.net/sysu_cis/article/details/52050072#t2

10、二叉树的所有路径

http://blog.csdn.net/sysu_cis/article/details/51771420

11、根节点到叶节点加法

http://blog.csdn.net/sysu_cis/article/details/51930079#t4


12、二叉树先序遍历

http://blog.csdn.net/sysu_cis/article/details/51834614#t3

13、二叉树中序遍历

http://blog.csdn.net/sysu_cis/article/details/51834614#t4

14、二叉树的后序遍历

http://blog.csdn.net/sysu_cis/article/details/52416773#t3

15、从中序遍历和后序遍历构造树

http://blog.csdn.net/sysu_cis/article/details/52041084#t3

16、从前序遍历和中序遍历构造树

http://blog.csdn.net/sysu_cis/article/details/52041084#t2

17、二叉树的层次遍历

http://blog.csdn.net/sysu_cis/article/details/51738240#t2

18、判断是否合法的BST

http://blog.csdn.net/sysu_cis/article/details/52416773#t2

19、验证一棵树是否合法

http://blog.csdn.net/sysu_cis/article/details/51934432#t6


20、找BST中第k小的元素

http://blog.csdn.net/sysu_cis/article/details/51837988#t4

21、将排序数组转换为BST

http://blog.csdn.net/sysu_cis/article/details/51858761#t3


22、二叉树从右边观察的值

http://blog.csdn.net/sysu_cis/article/details/51891799#t2

23、对二叉树增加next指针

http://blog.csdn.net/sysu_cis/article/details/51879907#t2


24、将一棵二叉树平铺成链表

http://blog.csdn.net/sysu_cis/article/details/51960141#t4

25、对称二叉树

http://blog.csdn.net/sysu_cis/article/details/51736673#t1



字符串


1、反转字符串中的元音

http://blog.csdn.net/sysu_cis/article/details/51723222

2、二进制加法    (给两个数字的二进制表示字符串,求加法)

http://blog.csdn.net/sysu_cis/article/details/51779664#t1

3、字符串乘法    (给两个数字的字符串表示,求乘法)

http://blog.csdn.net/sysu_cis/article/details/52374344#t2


4、同构字符串    (可以允许一些映射,求两个字符串映射之后是否相等)

http://blog.csdn.net/sysu_cis/article/details/51757743

5、模式匹配字符串

http://blog.csdn.net/sysu_cis/article/details/51762428#t4

6、判断括号合法性

http://blog.csdn.net/sysu_cis/article/details/51771420#t1

7、字符串中最后一个单词的长度

http://blog.csdn.net/sysu_cis/article/details/51771420#t3

8、合法的回文            (中间带有一些空格及其他内容)

http://blog.csdn.net/sysu_cis/article/details/51793202#t3

9、最长公共前缀                                                                                KMP

http://blog.csdn.net/sysu_cis/article/details/51775299#t4

10、字符串中的最长不包含重复字符的子串

​http://blog.csdn.net/sysu_cis/article/details/52733988#t4

11、比较版本号            (其实可以理解为比较两个数组大小)

http://blog.csdn.net/sysu_cis/article/details/51812720#t2

12、字符串转整型

http://blog.csdn.net/sysu_cis/article/details/51812720#t3

13、最长包含k次重复的子串

http://blog.csdn.net/sysu_cis/article/details/52543543#t3

14、颠倒字符的组        (给定一些字符串,按照字符个数相同的组成进行划分)

http://blog.csdn.net/sysu_cis/article/details/52059808#t2


15、ZigZag变换

http://blog.csdn.net/sysu_cis/article/details/51793202#t1

16、count and say

http://blog.csdn.net/sysu_cis/article/details/51771420#t2

17、Ransom Note     判断两个字符串是否含有相同字符组成

http://blog.csdn.net/sysu_cis/article/details/52330127#t2


回溯

1、生成括号

http://blog.csdn.net/sysu_cis/article/details/51849738#t4

2、电话号码组合

http://blog.csdn.net/sysu_cis/article/details/52016914#t4

3、组合加法            (集合元素可以使用多次)

http://blog.csdn.net/sysu_cis/article/details/51946182#t3

4、组合加法II            (集合元素只允许使用一次)

http://blog.csdn.net/sysu_cis/article/details/51946182#t4

5、组合加法III            (从1-9中选择k个数字和为n)

http://blog.csdn.net/sysu_cis/article/details/51858761#t5


6、格雷码

http://blog.csdn.net/sysu_cis/article/details/51866192#t3


7、排列                    (不包含重复元素)

http://blog.csdn.net/sysu_cis/article/details/51869692#t5

8、排列II                    (包含重复元素情况,找出所有不重复可能性)

http://blog.csdn.net/sysu_cis/article/details/52059808#t3

9、下一个排列

http://blog.csdn.net/sysu_cis/article/details/52426038#t3


10、组合

http://blog.csdn.net/sysu_cis/article/details/51869692#t3

11、数独解

http://blog.csdn.net/sysu_cis/article/details/52452337#t3

12、N皇后        (得出所有可行解)

http://blog.csdn.net/sysu_cis/article/details/52452337#t5

13、N皇后II        (得出所有可行解的个数)

http://blog.csdn.net/sysu_cis/article/details/52452337#t4


14、子集

http://blog.csdn.net/sysu_cis/article/details/51946182#t2

15、子集II

http://blog.csdn.net/sysu_cis/article/details/51975680#t3


16、回文分割

http://blog.csdn.net/sysu_cis/article/details/52157330#t4


动态规划

1、爬台阶

http://blog.csdn.net/sysu_cis/article/details/51708095


2、连续最大子序列和                                                                   DP--分治

http://blog.csdn.net/sysu_cis/article/details/51866192

3、连续最大子序列乘积

http://blog.csdn.net/sysu_cis/article/details/52367631#t3

4、买卖股票   (只允许一次买卖操作)                                DP--分治

http://blog.csdn.net/sysu_cis/article/details/51708095

5、买卖股票II(可以买卖多次)                                            贪心

http://blog.csdn.net/sysu_cis/article/details/51822901

6、买卖股票有冷却    (卖掉股票之后有一天冷却时间)        DP 

http://blog.csdn.net/sysu_cis/article/details/51866192


7、房子小偷            (一个数组中不能选择相邻元素如何取得最大值)

http://blog.csdn.net/sysu_cis/article/details/51723222

8、房子小偷II            (一个环路数组中不能选择相邻元素如何取得最大值)

http://blog.csdn.net/sysu_cis/article/details/51975680#t2

9、房子小偷III            (一棵树中不能选择相邻元素如何取得最大值)

http://blog.csdn.net/sysu_cis/article/details/51849738#t3


10、猜数字大小II    (每次猜错情况下,猜多少需要付出多少代价)

http://blog.csdn.net/sysu_cis/article/details/52133716#t4


11、组合加法 IV        (在nums中任意挑选数字,可多次,顺序任意,求有多少种组合方法)        DP

http://blog.csdn.net/sysu_cis/article/details/52031850#t2


12、区域和查询                (元素不变)

http://blog.csdn.net/sysu_cis/article/details/51779664#t3

13、计算n位数中不包含重复数字的整数个数

http://blog.csdn.net/sysu_cis/article/details/51822901#t3

14、整数分解使得其分解之后的数乘积最大

http://blog.csdn.net/sysu_cis/article/details/51822901#t4


15、唯一BST的个数

http://blog.csdn.net/sysu_cis/article/details/51858761#t2

16、唯一BST的个数II        (找到所有的BST)                                DP

http://blog.csdn.net/sysu_cis/article/details/52050072#t3


17、不同加括号的结果

http://blog.csdn.net/sysu_cis/article/details/51869692#t4


18、唯一路径

http://blog.csdn.net/sysu_cis/article/details/51866192#t5

19、唯一路径II        (中间有障碍)

http://blog.csdn.net/sysu_cis/article/details/52016914#t3

20、最小路径和    

http://blog.csdn.net/sysu_cis/article/details/51891799#t4

21、字符串正则匹配

http://blog.csdn.net/sysu_cis/article/details/52517659#t3



22、最大整除子集

http://blog.csdn.net/sysu_cis/article/details/52012006#t2


23、三角形

http://blog.csdn.net/sysu_cis/article/details/52004474#t0


24、编辑距离

http://blog.csdn.net/sysu_cis/article/details/52733988#t3


位运算

1、两个整数的加法与减法    (不用+和-实现)

http://blog.csdn.net/sysu_cis/article/details/51793202#t2

 2、二进制数字中1的位数

http://blog.csdn.net/sysu_cis/article/details/51705839

3、反转比特位

http://blog.csdn.net/sysu_cis/article/details/51775299#t1

4、统计1的位数           0-n之间每个数字包含1的位数                                                            DP

http://blog.csdn.net/sysu_cis/article/details/51814857#t1

5、数组中出现一次的数            (其他两次,一个数一次)

http://blog.csdn.net/sysu_cis/article/details/51814857#t2

6、数组中出现一次的数    II        (其他三次,一个一次)

http://blog.csdn.net/sysu_cis/article/details/51849738#t2

7、数组中出现一次的数    III        (其他两次,两个一次)

http://blog.csdn.net/sysu_cis/article/details/51814857#t3


8、数组中缺失的数                                                                            数学、位运算、排序查找

http://blog.csdn.net/sysu_cis/article/details/51834614#t2

9、不含重复字符的字符串最大长度乘积

http://blog.csdn.net/sysu_cis/article/details/51837988#t1


10、区间位与运算

http://blog.csdn.net/sysu_cis/article/details/52000291#t3


二分查找

1、猜数字大小

http://blog.csdn.net/sysu_cis/article/details/51901140#t2


2、第一个坏版本

http://blog.csdn.net/sysu_cis/article/details/51803048#t3

3、查找目标范围  (查找一个整数在一个整型数组中出现的范围)

http://blog.csdn.net/sysu_cis/article/details/52031850#t4

4、查找插入位置

http://blog.csdn.net/sysu_cis/article/details/51858761#t4

5、在有序矩阵中查找第k小的数

http://blog.csdn.net/sysu_cis/article/details/52090491#t3


6、在旋转有序数组中查找最小的数        (无重复元素)

http://blog.csdn.net/sysu_cis/article/details/51869692#t2

7、在旋转有序数组中查找最小的数II        (有重复元素)

http://blog.csdn.net/sysu_cis/article/details/52330127#t3

8、在旋转有序数组中查找某个值      

 http://blog.csdn.net/sysu_cis/article/details/52517659#t4


9、在旋转有序数组中查找某个值II        

http://blog.csdn.net/sysu_cis/article/details/51960141#t2


10、判断一个数是否平方数

http://blog.csdn.net/sysu_cis/article/details/51879907#t3


11、最长递增子序列

http://blog.csdn.net/sysu_cis/article/details/51921252#t2

12、递增三个元素的子序列

http://blog.csdn.net/sysu_cis/article/details/51921252#t4

13、二维矩阵中查找            (每行递增,下一行一定大于上一行)

http://blog.csdn.net/sysu_cis/article/details/51901140#t4

14、二维矩阵中的查找II    (每行递增,每列也递增)

http://blog.csdn.net/sysu_cis/article/details/51901140#t3

15、找到峰顶元素

http://blog.csdn.net/sysu_cis/article/details/51934432#t2


16、H指数

http://blog.csdn.net/sysu_cis/article/details/51934432#t4

17、H指数II

http://blog.csdn.net/sysu_cis/article/details/51934432#t5


18、在两个有序数组中查找中位数

http://blog.csdn.net/sysu_cis/article/details/52564096#t3


数学类

1、罗马数字转整型

http://blog.csdn.net/sysu_cis/article/details/51705839

2、整型数字转罗马数字

http://blog.csdn.net/sysu_cis/article/details/51837988


3、2的幂次

http://blog.csdn.net/sysu_cis/article/details/51723219

4、3的幂次

http://blog.csdn.net/sysu_cis/article/details/51723219

5、4的幂次

http://blog.csdn.net/sysu_cis/article/details/51736673

6、超级幂

http://blog.csdn.net/sysu_cis/article/details/52004474#t1

7、实现幂次函数pow(x,n)

http://blog.csdn.net/sysu_cis/article/details/52004474#t2

8、实现平方根函数sqrt(x)                                                    二分

http://blog.csdn.net/sysu_cis/article/details/52543543#t4

9、快乐数(各数位平方和最终为1)

http://blog.csdn.net/sysu_cis/article/details/51723219

10、丑数        (因子中只包含2,3,5)

http://blog.csdn.net/sysu_cis/article/details/51723219

11、丑数II      (找到第n个丑数)

http://blog.csdn.net/sysu_cis/article/details/52041084

12、超级丑数  (primes不再是2,3,5,而是给定的,思路完全一样)

http://blog.csdn.net/sysu_cis/article/details/51891799#t5


13、数位相加

http://blog.csdn.net/sysu_cis/article/details/52367631#t2

14、统计素数的个数

http://blog.csdn.net/sysu_cis/article/details/51779664#t4

15、完美平方数  (计算一个数最少能由多少个平方数相加而成)                    静态DP、BFS

http://blog.csdn.net/sysu_cis/article/details/51930079#t3


16、加1    (给定的是一个整型数字用数组来表示)

http://blog.csdn.net/sysu_cis/article/details/51730192

17、回文数字

http://blog.csdn.net/sysu_cis/article/details/51738240#t5

18、数独合法判断

http://blog.csdn.net/sysu_cis/article/details/51751141#t2


19、Bulls and Cows (猜数字,找出完全猜中的数字和只猜中值未猜中位置的数字)

http://blog.csdn.net/sysu_cis/article/details/51757743

20、矩形的面积    (给定两个矩形对角线点坐标,求矩形覆盖面积)

http://blog.csdn.net/sysu_cis/article/details/51757743#t4

21、阶乘后面0的数目

http://blog.csdn.net/sysu_cis/article/details/51738240#t3


22、反转整数

http://blog.csdn.net/sysu_cis/article/details/51803048#t1

23、EXCEL表格的列标题

http://blog.csdn.net/sysu_cis/article/details/51803048#t4

24、关灯问题

http://blog.csdn.net/sysu_cis/article/details/51834614#t1

25、分数转循环小数

http://blog.csdn.net/sysu_cis/article/details/52426038#t2

1、课程表                (有向图是否有环)

http://blog.csdn.net/sysu_cis/article/details/52164467#t4

贪心

1、跳跃游戏

http://blog.csdn.net/sysu_cis/article/details/52157330#t3

2、摇摆子序列                                                                                            贪心(为什么可以贪心?)

http://blog.csdn.net/sysu_cis/article/details/52000291#t2

3、加油站

http://blog.csdn.net/sysu_cis/article/details/52170574#t2


实现类

1、用队列实现栈

http://blog.csdn.net/sysu_cis/article/details/51757743#t1

2、用栈实现队列

http://blog.csdn.net/sysu_cis/article/details/51736673#t3

3、实现最小栈

http://blog.csdn.net/sysu_cis/article/details/51803048#t2

4、二叉树迭代器

http://blog.csdn.net/sysu_cis/article/details/51891799#t3

5、顶端迭代器

http://blog.csdn.net/sysu_cis/article/details/51930079#t2

6、展平迭代器

http://blog.csdn.net/sysu_cis/article/details/51960141#t4

7、插入删除获得随机元素 O(1)复杂度     (不允许重复元素)

http://blog.csdn.net/sysu_cis/article/details/52133716#t3

8、插入删除获得随机元素 O(1)复杂度     (允许重复元素)

http://blog.csdn.net/sysu_cis/article/details/52164467#t3


未记录

1、反转字符串

2、猜石头游戏

3、二叉树最大深度

4、转化二叉树

5、删除数组中所有的0

6、删除链表中的一个节点

7、相同的树

8、excel表的列号

9、合法的回文构词法

10、众数



你可能感兴趣的:(leetcode)