摘要:
LeetCode 216.组合总和III 分析1.0 回溯问题 组合总和sum == n 时以及path中元素个数 == k 时,res.add(new path) 返回后递归删除掉当前值 class Solution { public List<List<Integer>> res = new A 阅读全文
摘要:
LeetCode 530.二叉搜索树的最小绝对差 分析1.0 二叉搜索树,中序遍历形成一个升序数组,节点差最小值一定在中序遍历两个相邻节点产生 ✡✡✡ 即 双指针思想在树遍历中的应用 class Solution { TreeNode pre;// 记录上一个遍历的结点 int result = I 阅读全文
摘要:
基础知识 二叉树的多种遍历方式,每种遍历方式各有其特点 LeetCode 104.二叉树的最大深度 分析1.0 往下遍历深度++,往上回溯深度-- class Solution { int deep = 0, max = 0; public int maxDepth(TreeNode root) { 阅读全文
摘要:
层序遍历 /** * 二叉树的层序遍历 */ class QueueTraverse { /** * 存放一层一层的数据 */ public List<List<Integer>> resList = new ArrayList<>(); public List<List<Integer>> lev 阅读全文
摘要:
基础知识 二叉树基础知识 二叉树多考察完全二叉树、满二叉树,可以分为链式存储和数组存储,父子兄弟访问方式也有所不同,遍历也分为了前中后序遍历和层次遍历 Java定义 public class TreeNode { int val; TreeNode left; TreeNode right; Tre 阅读全文
摘要:
基础知识 String StringBuilder 操作 public class StringOperation { int startIndex; int endIndex; { //初始容量为16个字符 主要做增删查改 索引包头不包尾 StringBuilder sb = new String 阅读全文