LeetCode总结
LeetCode总结
所有代码见我的github。不过一般leetcode上答案也一大堆,最好还是自己动动手,收获比较大。
100
知识点:递归,二叉树
难度Easy,主要是注意对当p和q均为null时也要做判断。
104
知识点:二叉树,DFS
难度Easy,递归返回的时候记得+1
136
知识点:哈希表,位操作
难度Easy,一个哈希表搞定。但是用XOR的思想实现O(n) time complexity and O(1) space complexity新手不太容易想到。
因为A XOR A = 0,且XOR运算是可交换的,于是,对于实例{2,1,4,5,2,4,1}就会有这样的结果:
(2^1^4^5^2^4^1) => ((2^2)^(1^1)^(4^4)^(5)) => (0^0^0^5) => 5
就把只出现了一次的元素(其余元素均出现两次)给找出来了!
191
知识点:位操作
难度Easy,位操作的基本题型吧,要是不熟悉位操作,可以好好学习一下这个题目
217
知识点:数组,哈希表
难度Easy,这个题目真是经典,方法太多了。我自己的思路是把list放到set里,然后比较大小。看了讨论里面还有其他的方法,一起说一说。
第一种是最简单的循环两遍。第二种是先排序,然后遍历一遍,比较相邻的元素是否相等。第三种是利用哈希表,先遍历一遍然后看看哪个元素出现了两次
226
知识点:二叉树,递归
难度Easy,递归+二叉树没少考。
237
知识点:链表
难度Easy,链表的入门题目了吧,直接把下一个节点的所有信息覆盖到该节点就行
LeetCode总结的更多相关文章
- 我为什么要写LeetCode的博客?
# 增强学习成果 有一个研究成果,在学习中传授他人知识和讨论是最高效的做法,而看书则是最低效的做法(具体研究成果没找到地址).我写LeetCode博客主要目的是增强学习成果.当然,我也想出名,然而不知 ...
- LeetCode All in One 题目讲解汇总(持续更新中...)
终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...
- [LeetCode] Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子字符串
Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...
- Leetcode 笔记 113 - Path Sum II
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...
- Leetcode 笔记 112 - Path Sum
题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...
- Leetcode 笔记 110 - Balanced Binary Tree
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...
- Leetcode 笔记 100 - Same Tree
题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or ...
- Leetcode 笔记 99 - Recover Binary Search Tree
题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...
- Leetcode 笔记 98 - Validate Binary Search Tree
题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binar ...
- Leetcode 笔记 101 - Symmetric Tree
题目链接:Symmetric Tree | LeetCode OJ Given a binary tree, check whether it is a mirror of itself (ie, s ...
随机推荐
- Custom Settings.ini 和 bootstrap.ini 配置
[Settings]Priority=DefaultProperties=MyCustomProperty [Default] ;SkipWizard=YES 如果跳过部署向导,则即使 SkipCap ...
- (1)String类 (2)StringBuilder类和StringBuffer类 (3)日期相关的类
1.String类(重中之重)1.1 常用的方法(练熟.记住)(1)常用的构造方法 String() - 使用无参的方式构造空字符串对象. String(byte[] bytes) - 根据参数指定的 ...
- PHP设计模式系列 - 适配器
什么是适配器: 适配器设计模式只是将某个对象的接口适配为另一个对象所期望的接口. 设计情景: 假如我们原始的有一个UserInfo的类,提供用户信息的类,早起设计该类的时候,只实现了一个getUser ...
- java内部类案例
实现键值对的存储输出 import java.util.Arrays; public class EntryDemoTest { //实现键值对的存储 public static void main( ...
- CSS 构造表格
表格边框 CSS 中设置表格边框,请使用 border 属性: <style type="text/css"> table{ border:1px solid red; ...
- swift内存管理:值类型与引用类型
Use struct to create a structure. Structures support many of the same behaviors as classes, includin ...
- kvo的observationInfo
观察者信息的注册: <NSKeyValueObservationInfo 0x600000708d60> ( <NSKeyValueObservance 0x6000009143f0 ...
- 【bzoj4543】[POI2014]Hotel加强版
题目 抄题解.jpg 发现原来的\(O(n^2)\)的换根\(dp\)好像行不通了呀 我们考虑非常牛逼的长链剖分 我们设\(f[x][j]\)表示在\(x\)的子树中距离\(x\)为\(j\)的点有多 ...
- POJ Football Game 【NIMK博弈 && Bash 博弈】
Football Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 451 Accepted: 178 Descr ...
- docker 导入导出镜像
docker容器导入导出有两种方法: 一种是使用save和load命令 使用例子如下: docker save ubuntu:load>/root/ubuntu.tar docker load& ...