04 2020 档案

摘要:``` /** * 114. Flatten Binary Tree to Linked List * 1. Time:O(n) Space:O(logn) * 2. Time:O(n) Space:O(1) * 3. Time:O(n) Space:O(logn) */ // 1. Time:O(n) Space:O(logn) class Solution { public void flat 阅读全文
posted @ 2020-04-29 11:14 AAAmsl 阅读(97) 评论(0) 推荐(0)
摘要:``` /** * 110. Balanced Binary Tree * 1. Time:O(n) Space:O(logn) */ // 1. Time:O(n) Space:O(logn) class Solution { public boolean isBalanced(TreeNode root) { return helper(root)>=0; } public int helpe 阅读全文
posted @ 2020-04-29 11:13 AAAmsl 阅读(78) 评论(0) 推荐(0)
摘要:``` /** * 101. Symmetric Tree * 1. Time:O(n) Space:O(n) * 2. Time:O(n) Space:O(n) */ // 1. Time:O(n) Space:O(n) class Solution { public boolean isSymmetric(TreeNode root) { return isMirror(root,root); 阅读全文
posted @ 2020-04-29 11:12 AAAmsl 阅读(95) 评论(0) 推荐(0)
摘要:``` /** * 100. Same Tree * 1. Time:O(n) Space:O(n) * 2. Time:O(n) Space:O(n) */ // 1. Time:O(n) Space:O(n) class Solution { public boolean isSameTree(TreeNode p, TreeNode q) { if(p==null && q==null) r 阅读全文
posted @ 2020-04-29 11:11 AAAmsl 阅读(63) 评论(0) 推荐(0)
摘要:```/** * 99. Recover Binary Search Tree * 1. Time:O(n) Space:O(logn) * 2. Time:O(n) Space:O(1) */// 1. Time:O(n) Space:O(logn)class Solution { TreeNode p1 = null; TreeNode p2 = null; T... 阅读全文
posted @ 2020-04-29 11:10 AAAmsl 阅读(73) 评论(0) 推荐(0)
摘要:``` /** * 103. Binary Tree Zigzag Level Order Traversal * 1. Time:O(n) Space:O(n) * 2. Time:O(n) Space:O(n) */ // 1. Time:O(n) Space:O(n) class Solution { public List> zigzagLevelOrder(TreeNode root) 阅读全文
posted @ 2020-04-29 11:09 AAAmsl 阅读(73) 评论(0) 推荐(0)
摘要:```/** * 173. Binary Search Tree Iterator * 1. Time:O() Space:O() * 2. Time:O() Space:O() */// 1. Time:O() Space:O()class BSTIterator { ArrayList res; int index; public BSTIterator(Tre... 阅读全文
posted @ 2020-04-28 13:58 AAAmsl 阅读(70) 评论(0) 推荐(0)
摘要:```/** * 226. Invert Binary Tree * 1. Time:O(n) Space:O(n) * 2. Time:O(n) Space:O(n) */// 1. Time:O(n) Space:O(n)class Solution { public TreeNode invertTree(TreeNode root) { if(root==null... 阅读全文
posted @ 2020-04-28 13:57 AAAmsl 阅读(67) 评论(0) 推荐(0)
摘要:``` /** * 199. Binary Tree Right Side View * 1. Time:O(n) Space:O(n) * 2. Time:O(n) Space:O(n) */ // 1. Time:O(n) Space:O(n) class Solution { public List rightSideView(TreeNode root) { List res = new 阅读全文
posted @ 2020-04-28 13:56 AAAmsl 阅读(74) 评论(0) 推荐(0)
摘要:```/** * 107. Binary Tree Level Order Traversal II * 1. Time:O(n) Space:O(n) * 2. Time:O(n) Space:O(n) */// 1. Time:O(n) Space:O(n)class Solution { public List> levelOrderBottom(TreeNode root) {... 阅读全文
posted @ 2020-04-28 13:54 AAAmsl 阅读(69) 评论(0) 推荐(0)
摘要:``` /** * 102. Binary Tree Level Order Traversal * 1. Time:O(n) Space:O(n) * 2. Time:O(n) Space:O(n) */ // 1. Time:O(n) Space:O(n) class Solution { public List> levelOrder(TreeNode root) { List> res = 阅读全文
posted @ 2020-04-27 12:07 AAAmsl 阅读(67) 评论(0) 推荐(0)
摘要:```/** * 145. Binary Tree Postorder Traversal * 1. Time:O(n) Space:O(n) * 2. Time:O(n) Space:O(n) * 3. Time:O(n) Space:O(n) * 4. Time:O(n) Space:O(1) */// 1. Time:O(n) Space:O(n)class Solution { ... 阅读全文
posted @ 2020-04-27 12:05 AAAmsl 阅读(64) 评论(0) 推荐(0)
摘要:```/** * 94. Binary Tree Inorder Traversal * 1. Time:O(n) Space:O(n) * 2. Time:O(n) Space:O(n) * 3. Time:O(n) Space:O(1) */// 1. Time:O(n) Space:O(n)class Solution { public List inorderTraversa... 阅读全文
posted @ 2020-04-27 12:04 AAAmsl 阅读(80) 评论(0) 推荐(0)
摘要:```/** * 144. Binary Tree Preorder Traversal * 1. Time:O(n) Space:O(n) * 2. Time:O(n) Space:O(n) * 3. Time:O(n) Space:O(n) * 4. Time:O(n) Space:O(1) */// 1. Time:O(n) Space:O(n)class Solution { ... 阅读全文
posted @ 2020-04-27 12:03 AAAmsl 阅读(58) 评论(0) 推荐(0)
摘要:代码 解释 public 访问修饰符,控制程序的其他部分对这段代码的访问级别 class 关键字,表示类 FirstSample 类名 Java中类名的命名规定 以字母开头,后面可以跟字母和数字的任意组合,长度基本上没有限制 类名不能是Java保留字 main方法 Java 1.4之后强制main方 阅读全文
posted @ 2020-04-27 11:59 AAAmsl 阅读(145) 评论(0) 推荐(0)