摘要: ```/** * 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 阅读(75) 评论(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 阅读(67) 评论(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 阅读(55) 评论(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 阅读(68) 评论(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 阅读(82) 评论(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 阅读(58) 评论(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 阅读(75) 评论(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 阅读(62) 评论(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 阅读(64) 评论(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 阅读(88) 评论(0) 推荐(0) 编辑