05 2022 档案
106. 从中序与后序遍历序列构造二叉树
摘要:package leetcode; import java.util.HashMap; public class demo_106 { public TreeNode buildTree(int[] inorder, int[] postorder) { HashMap<Integer, Integ 阅读全文
posted @ 2022-05-17 10:16 一仟零一夜丶 阅读(22) 评论(0) 推荐(0)
208. 实现 Trie (前缀树)
摘要:package leetcode; class Trie { private Trie[] children; //当前节点是否为一个单词的结尾 private boolean isEnd; public Trie() { //每个节点最多有26个字母 children=new Trie[26]; 阅读全文
posted @ 2022-05-16 11:25 一仟零一夜丶 阅读(53) 评论(0) 推荐(0)
114. 二叉树展开为链表
摘要:package leetcode; public class demo_114 { //从最后一个节点倒着插入到链表中 TreeNode lastNode=null; public void flatten(TreeNode root) { if(root==null) { return; } // 阅读全文
posted @ 2022-05-09 10:34 一仟零一夜丶 阅读(23) 评论(0) 推荐(0)
105. 从前序与中序遍历序列构造二叉树
摘要:package leetcode; import java.util.HashMap; public class demo_105 { public TreeNode buildTree(int[] preorder, int[] inorder) { HashMap<Integer, Intege 阅读全文
posted @ 2022-05-07 15:23 一仟零一夜丶 阅读(17) 评论(0) 推荐(0)
617. 合并二叉树
摘要:package leetcode; public class demo_617 { public TreeNode mergeTrees(TreeNode root1, TreeNode root2) { //root1为空,直接返回root2剩余部分 if(root1==null) {return 阅读全文
posted @ 2022-05-07 10:57 一仟零一夜丶 阅读(24) 评论(0) 推荐(0)
98. 验证二叉搜索树
摘要:package leetcode; import java.util.Stack; public class demo_98 { public boolean isValidBST(TreeNode root) { Stack<TreeNode> stack=new Stack<TreeNode>( 阅读全文
posted @ 2022-05-06 11:22 一仟零一夜丶 阅读(20) 评论(0) 推荐(0)
96. 不同的二叉搜索树
摘要:package leetcode; public class demo_96 { public int numTrees(int n) { int[] dp=new int[n+1]; dp[0]=1; dp[1]=1; //按每一个数作为一次根节点,累计左右子树的可能性 for(int i=2;i 阅读全文
posted @ 2022-05-06 10:16 一仟零一夜丶 阅读(19) 评论(0) 推荐(0)
543. 二叉树的直径
摘要:package leetcode; public class demo_543 { int max=0; public int diameterOfBinaryTree(TreeNode root) { order(root); return max; } public void order(Tre 阅读全文
posted @ 2022-05-05 11:03 一仟零一夜丶 阅读(37) 评论(0) 推荐(0)
234. 回文链表
摘要:package leetcode; public class demo_234 { public boolean isPalindrome(ListNode head) { if(head==null||head.next==null) {return true;} ListNode slow=he 阅读全文
posted @ 2022-05-04 11:46 一仟零一夜丶 阅读(28) 评论(0) 推荐(0)
101. 对称二叉树
摘要:package leetcode; public class demo_101 { public boolean isSymmetric(TreeNode root) { if(root==null) { return true; } return function(root.left, root. 阅读全文
posted @ 2022-05-04 10:08 一仟零一夜丶 阅读(21) 评论(0) 推荐(0)
394. 字符串解码
摘要:package leetcode; import java.util.Stack; public class demo_394 { public String decodeString(String s) { StringBuffer sb=new StringBuffer(); StringBuf 阅读全文
posted @ 2022-05-03 15:07 一仟零一夜丶 阅读(40) 评论(0) 推荐(0)
347. 前 K 个高频元素
摘要:package leetcode; import java.util.Comparator; import java.util.HashMap; import java.util.Map; import java.util.PriorityQueue; import java.util.Set; p 阅读全文
posted @ 2022-05-02 11:51 一仟零一夜丶 阅读(37) 评论(0) 推荐(0)
279. 完全平方数
摘要:package leetcode; import java.util.Arrays; public class demo_279 { public int numSquares(int n) { if(n==1) {return 1;} //动态规划 int[] dp=new int[n+1]; / 阅读全文
posted @ 2022-05-02 10:31 一仟零一夜丶 阅读(36) 评论(0) 推荐(0)