05 2020 档案

摘要:```/** * 21. Merge Two Sorted Lists * 1. Time:O(min(m,n)) Space:O(1) * 2. Time:O(m+n) Space:O(m+n) */// 1. Time:O(min(m,n)) Space:O(1)class Solution { public ListNode mergeTwoLists(ListNode l1, Lis... 阅读全文
posted @ 2020-05-10 10:44 AAAmsl 阅读(80) 评论(0) 推荐(0)
摘要:``` /** * 88. Merge Sorted Array * 1. Time:O(m+n) Space:O(m) * 2. Time:O(m+n) Space:O(1) */ // 1. Time:O(m+n) Space:O(m) class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { in 阅读全文
posted @ 2020-05-10 10:43 AAAmsl 阅读(75) 评论(0) 推荐(0)
摘要:``` /** * 147. Insertion Sort List * 1. Time:O(n2) Space:O(1) * 2. Time:O(n2) Space:O(1) */ // 1. Time:O(n2) Space:O(1) class Solution { public ListNode insertionSortList(ListNode head) { ListNode dum 阅读全文
posted @ 2020-05-10 10:42 AAAmsl 阅读(63) 评论(0) 推荐(0)
摘要:``` /** * 307. Range Sum Query - Mutable * 1. Time:O(n) Space:O(1) * 2. Time:O(logn) Space:O(1) * 3. Time:O(logn) Space:O(1) */ // 1. Time:O(n) Space:O(1) class NumArray { private int[] nums; public N 阅读全文
posted @ 2020-05-10 10:40 AAAmsl 阅读(83) 评论(0) 推荐(0)
摘要:``` /** * 236. Lowest Common Ancestor of a Binary Tree * 1. Time:O(n) Space:O(h) * 2. Time:O(n) Space:O(n) */ // 1. Time:O(n) Space:O(h) class Solution { public TreeNode lowestCommonAncestor(TreeNode 阅读全文
posted @ 2020-05-09 09:34 AAAmsl 阅读(95) 评论(0) 推荐(0)
摘要:```/** * 129. Sum Root to Leaf Numbers * 1. Time:O(n) Space:O(logn) * 2. Time:O(n) Space:O(n) */// 1. Time:O(n) Space:O(logn)class Solution { public int sumNumbers(TreeNode root) { return... 阅读全文
posted @ 2020-05-09 09:31 AAAmsl 阅读(66) 评论(0) 推荐(0)
摘要:```/** * 124. Binary Tree Maximum Path Sum * 1. Time:O(n) Space:O(logn) */// 1. Time:O(n) Space:O(logn)class Solution { private int maxSum = Integer.MIN_VALUE; public int maxPathSum(Tr... 阅读全文
posted @ 2020-05-09 09:29 AAAmsl 阅读(79) 评论(0) 推荐(0)
摘要:``` /** * 113. Path Sum II * 1. Time:O(n) Space:O(n) */ // 1. Time:O(n) Space:O(n) class Solution { public List> pathSum(TreeNode root, int sum) { List> res = new ArrayList(); helper(root,sum,res,new 阅读全文
posted @ 2020-05-09 09:27 AAAmsl 阅读(71) 评论(0) 推荐(0)
摘要:``` /** * 112. Path Sum * 1. Time:O(n) Space:O(h) * 2. Time:O(n) Space:O(h) */ // 1. Time:O(n) Space:O(h) class Solution { public boolean hasPathSum(TreeNode root, int sum) { if(root==null) return fal 阅读全文
posted @ 2020-05-08 11:12 AAAmsl 阅读(69) 评论(0) 推荐(0)
摘要:``` /** * 111. Minimum Depth of Binary Tree * 1. Time:O(n) Space:O(h) * 2. Time:O(n) Space:O(h) */ // 1. Time:O(n) Space:O(h) class Solution { public int minDepth(TreeNode root) { if(root==null) retur 阅读全文
posted @ 2020-05-08 11:10 AAAmsl 阅读(96) 评论(0) 推荐(0)
摘要:``` /** * 104. Maximum Depth of Binary Tree * 1. Time:O(n) Space:O(h) * 2. Time:O(n) Space:O(h) * 3. Time:O(n) Space:O(h) */ // 1. Time:O(n) Space:O(h) class Solution { public int maxDepth(TreeNode ro 阅读全文
posted @ 2020-05-08 11:08 AAAmsl 阅读(72) 评论(0) 推荐(0)
摘要:```/** * 230. Kth Smallest Element in a BST * 1. Time:O(n) Space:O(n) * 2. Time:O(h+k) Space:O(h+k) * 3. Time:O(h+k) Space:O(h+k) */// 1. Time:O(n) Space:O(n)class Solution { public int kthSmal... 阅读全文
posted @ 2020-05-08 11:07 AAAmsl 阅读(54) 评论(0) 推荐(0)
摘要:```/** * 235. Lowest Common Ancestor of a Binary Search Tree * 1. Time:O(n) Space:O(n) * 2. Time:O(n) Space:O(1) */// 1. Time:O(n) Space:O(n)class Solution { public TreeNode lowestCommonAncestor... 阅读全文
posted @ 2020-05-07 12:00 AAAmsl 阅读(87) 评论(0) 推荐(0)
摘要:``` /** * 109. Convert Sorted List to Binary Search Tree * 1. Time:O(nlogn) Space:O(logn) * 2. Time:O(n) Space:O(logn) */ // 1. Time:O(nlogn) Space:O(logn) class Solution { public TreeNode sortedListT 阅读全文
posted @ 2020-05-07 11:58 AAAmsl 阅读(60) 评论(0) 推荐(0)
摘要:``` /** * 108. Convert Sorted Array to Binary Search Tree * 1. Time:O(n) Space:O(n) * 2. Time:O(n) Space:O(n) */ // 1. Time:O(n) Space:O(n) class Solution { private int[] nums; public TreeNode sortedA 阅读全文
posted @ 2020-05-07 11:57 AAAmsl 阅读(94) 评论(0) 推荐(0)
摘要:``` /** * 98. Validate Binary Search 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 isValidBST(TreeNode root) { return helper(ro 阅读全文
posted @ 2020-05-07 11:56 AAAmsl 阅读(67) 评论(0) 推荐(0)