1.链表
1.返回链表上中点
2.返回链表下中点
3.链表是否有环
4.有环就返回入环节点,否则返回null
4.找到两个单链表相交的起始节点,没有就返回null
5.反转链表
- 非递归
- 递归
2.栈,队列
1.最小栈
3.数组
1.多数元素
2.数组中重复的数字
3.查找旋转数组最小元素
4. 0~n-1中缺失的数字
5.扑克牌中的顺子
4.位运算
1.汉明距离
2. 二进制中1的个数
5.二叉树
1.合并二叉树
6.递归
错误的解
字符串拼接会生成一个新的字符串
7.plus题目
426
class Solution {
public List<Integer> boundaryOfBinaryTree(TreeNode root) {
List<Integer> res = new ArrayList();
if(root == null) return res;
if(isLeaf(root)){
res.add(root.val);
return res;
}
res.add(root.val);
leftBoundary(root.left,res);
leafBoundary(root,res);
rightBoundary(root.right,res);
return res;
}
public void leftBoundary(TreeNode node,List<Integer> res){
if(node == null) return;
if(!isLeaf(node)){
res.add(node.val);
}
if(node.left != null){
leftBoundary(node.left,res);
}else{
leftBoundary(node.right,res);
}
}
public void rightBoundary(TreeNode node,List<Integer> res){
if(node == null) return;
//因为按顺序返回,左侧边界是从上到下,右侧边界是从下到上的
if(node.right != null){
rightBoundary(node.right,res);
}else{
rightBoundary(node.left,res);
}
if(!isLeaf(node)){
res.add(node.val);
}
}
public void leafBoundary(TreeNode node,List<Integer> res){
if(node == null) return;
if(isLeaf(node)){
res.add(node.val);
}
leafBoundary(node.left,res);
leafBoundary(node.right,res);
}
public boolean isLeaf(TreeNode node){
return node.left == null && node.right == null;
}
}