摘要: 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)
摘要: Sqrt(x) 思路一: 暴力 public int mySqrt(int x) { long begin = 1L; while ((begin * begin) <= x) { begin++; } return Long.valueOf(begin).intValue() - 1; } 思路二 阅读全文
posted @ 2022-10-12 18:48 iyiluo 阅读(13) 评论(0) 推荐(0)
摘要: 问题: docker-compose 启动 java 容器时报错 library initialization failed - unable to allocate file descriptor table - out of memoryPicked up JAVA_TOOL_OPTIONS: 阅读全文
posted @ 2022-10-12 18:47 iyiluo 阅读(5297) 评论(0) 推荐(1)
摘要: Add Binary 思路一: 先计算公共部分,最后补充未计算的位置,模拟二进制加法,写的太丑了 public String addBinary(String a, String b) { char ONE = '0' + '1'; char TWO = '1' + '1'; StringBuild 阅读全文
posted @ 2022-10-11 22:13 iyiluo 阅读(22) 评论(0) 推荐(0)
摘要: Plus One 思路一: 暴力,方向想错了,不能把 digits 当做一个整数看 public int[] plusOne(int[] digits) { if (digits[digits.length - 1] != 9) { digits[digits.length - 1]++; retu 阅读全文
posted @ 2022-10-11 17:59 iyiluo 阅读(16) 评论(0) 推荐(0)
摘要: Length of Last Word 思路一: 从后面非空格字符开始扫描,记录非空格字符个数。优化:不用 char[],直接用 charAt() 判断 public int lengthOfLastWord(String s) { char[] chars = s.toCharArray(); i 阅读全文
posted @ 2022-10-11 17:59 iyiluo 阅读(12) 评论(0) 推荐(0)