上一页 1 ··· 13 14 15 16 17 18 19 20 21 ··· 36 下一页
摘要: 回溯 import java.util.ArrayList; import java.util.LinkedList; import java.util.List; class Solution { List<List<String>> list = new ArrayList<>(); Linke 阅读全文
posted @ 2022-01-11 21:06 振袖秋枫问红叶 阅读(41) 评论(0) 推荐(1)
摘要: 回溯 import java.util.ArrayList; import java.util.LinkedList; import java.util.List; class Solution { List<List<Integer>> list = new ArrayList<>(); Link 阅读全文
posted @ 2022-01-11 16:16 振袖秋枫问红叶 阅读(37) 评论(0) 推荐(1)
摘要: 回溯 import java.util.ArrayList; import java.util.LinkedList; import java.util.List; class Solution { List<List<Integer>> list = new ArrayList<>(); Link 阅读全文
posted @ 2022-01-11 15:18 振袖秋枫问红叶 阅读(41) 评论(0) 推荐(1)
摘要: 深度优先搜索 import java.util.ArrayList; import java.util.List; class Solution { /** * 全局变量存储结果 */ List<String> list = new ArrayList<>(); /** * 哈希表存储数字和字母的对 阅读全文
posted @ 2022-01-10 15:19 振袖秋枫问红叶 阅读(83) 评论(0) 推荐(0)
摘要: 递归 class Solution { public TreeNode deleteNode(TreeNode root, int key) { if (root == null){ return root; } /** * 如果大于当前节点,就在左子树寻找;小于则在右子树寻找 * 相等则分三种情况 阅读全文
posted @ 2022-01-05 17:30 振袖秋枫问红叶 阅读(41) 评论(0) 推荐(0)
摘要: 中序遍历 class Solution { public boolean isValidBST(TreeNode root) { ArrayList<Integer> list = new ArrayList<>(); inorder(root, list); /** * 中序遍历得到列表,判断列表 阅读全文
posted @ 2022-01-05 16:04 振袖秋枫问红叶 阅读(28) 评论(0) 推荐(0)
摘要: 中序遍历 class Solution { public int kthSmallest(TreeNode root, int k) { ArrayList<Integer> list = new ArrayList<>(); inorder(root, list); return list.get 阅读全文
posted @ 2022-01-05 15:16 振袖秋枫问红叶 阅读(15) 评论(0) 推荐(0)
摘要: 二分查找 class Solution { public TreeNode sortedArrayToBST(int[] nums) { return sortedArrayToBST(nums, 0, nums.length - 1); } /** * 每次将数组的中间元素作为根节点,这样得到的二 阅读全文
posted @ 2022-01-05 14:51 振袖秋枫问红叶 阅读(41) 评论(0) 推荐(0)
摘要: 深度优先搜索 class Solution { /** * 因为和有可能为负数,因此初始值取无穷小 */ int max = Integer.MIN_VALUE; public int maxPathSum(TreeNode root) { maxSum(root); return max; } / 阅读全文
posted @ 2021-12-29 20:05 振袖秋枫问红叶 阅读(38) 评论(0) 推荐(0)
摘要: 深度优先搜索 class Solution { int maxLength = 0; public int longestUnivaluePath(TreeNode root) { depth(root); return maxLength; } /** * 在《104. 二叉树的最大深度》的基础上 阅读全文
posted @ 2021-12-29 10:23 振袖秋枫问红叶 阅读(25) 评论(0) 推荐(0)
上一页 1 ··· 13 14 15 16 17 18 19 20 21 ··· 36 下一页