摘要:
Same Tree public boolean isSameTree(TreeNode p, TreeNode q) { if (p == null && q == null) return true; if (p != null && q == null) return false; if (p 阅读全文
posted @ 2022-10-13 18:01
iyiluo
阅读(13)
评论(0)
推荐(0)
摘要:
Binary Tree Inorder Traversal public List<Integer> inorderTraversal(TreeNode root) { List<Integer> list = new ArrayList<>(); t(root, list); return lis 阅读全文
posted @ 2022-10-13 18:01
iyiluo
阅读(11)
评论(0)
推荐(0)
摘要:
Merge Sorted Array 思路一: 比较两个数组前面最小值,依次插入到新数组中,最后复制新数组到 num1 中 public void merge(int[] nums1, int m, int[] nums2, int n) { int[] result = new int[nums1 阅读全文
posted @ 2022-10-13 18:01
iyiluo
阅读(16)
评论(0)
推荐(0)
摘要:
Remove Duplicates from Sorted List 思路一: 双指针,左指针记录链表最后有效位置,右指针向前扫描,遇到不重复的值,加到左指针后面,双指针依次向前 public ListNode deleteDuplicates(ListNode head) { if (head = 阅读全文
posted @ 2022-10-13 18:00
iyiluo
阅读(12)
评论(0)
推荐(0)
摘要:
Climbing Stairs 思路一: 动态规划,假设爬上第 n 阶楼梯,完全分类只可能存在两种情况 在 n-1 楼梯处直接一步上来 在 n-2 楼梯处直接两步上来 所以 爬上第 n 阶楼梯的方法: f(n) = f(n-1) + f(n+1) public int climbStairs(int 阅读全文
posted @ 2022-10-13 09:19
iyiluo
阅读(19)
评论(0)
推荐(0)