剑指
laohixdxm00
这个作者很懒,什么都没留下…
展开
-
剑指 Offer 16. 数值的整数次方
https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/submissions/ [bug] 1 index from what? 2 negative 3 what will overflow [wrong code] class Solution { Map<Integer, Double> map = new HashMap<>(); public double myPow(doub原创 2021-05-16 20:44:53 · 58 阅读 · 0 评论 -
剑指 Offer 42. 连续子数组的最大和
https://leetcode-cn.com/problems/lian-xu-zi-shu-zu-de-zui-da-he-lcof/ [wrong code] class Solution { public int maxSubArray(int[] nums) { int n = nums.length; return d_c(0, n-1, nums); } int d_c(int l, int r, int[] nums){原创 2021-05-15 13:09:27 · 36 阅读 · 0 评论 -
剑指 Offer 31. 栈的压入、弹出序列
https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/ [cases] 1 2 3 4 5 | 4 5 3 2 1 1 2 3 4 5 | 4 3 5 2 1 1 2 3 3 4 5 6 | 4 6 5 3 2 1 [wrong code] class Solution { public boolean validateStackSequences(int[] pushed, int[] popped) {原创 2021-05-14 19:38:11 · 45 阅读 · 0 评论 -
剑指 Offer 13. 机器人的运动范围
https://leetcode-cn.com/problems/ji-qi-ren-de-yun-dong-fan-wei-lcof/ [bug] 1 (0,0) clarify to interviewer, can (0,0) be counted? 2 大于k [wrong code] class Solution { int[][] dirs = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}}; int h, w, k; boolean[][] vi原创 2021-05-13 17:05:55 · 45 阅读 · 0 评论 -
剑指 Offer 12. 矩阵中的路径
https://leetcode-cn.com/problems/ju-zhen-zhong-de-lu-jing-lcof/ [bug] 1 why not multiple BFS run parallel? 2 edge case cannot reach “return true” 3 wrong case a b |“abcd” c d [wrong code] class Solution { int[][] dirs = {{0,-1}, {0,1}, {-1,0}, {1,0}原创 2021-05-13 15:39:36 · 48 阅读 · 0 评论 -
剑指 Offer 42. 连续子数组的最大和
https://leetcode-cn.com/problems/lian-xu-zi-shu-zu-de-zui-da-he-lcof/ [assumption] move left to right whenever sum<0, start from next element. [get assumption] [prove assumption]原创 2021-05-12 12:58:19 · 40 阅读 · 0 评论 -
剑指 Offer 39. 数组中出现次数超过一半的数字 LCOF [lc169] [书上的解法2]
https://leetcode-cn.com/problems/majority-element/ algo: 利用 target的数目比其他数字的数目都多。 key is number of target is more than the number of all other number. make use of this assume target = 2 |3…3 | 4…4|2…2 一半2 | 一半2 | 多于一半2 |3…3|4…4| 3…3 一半2 | 没有3 | 多于一半3 last i原创 2021-05-12 11:48:15 · 59 阅读 · 0 评论 -
剑指 Offer 39. 数组中出现次数超过一半的数字 LCOF [lc169]
https://leetcode-cn.com/problems/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof/ [wrong code] class Solution { public int majorityElement(int[] nums) { int l = 0; int n = nums.length; int r = n-1;原创 2021-05-11 21:00:38 · 86 阅读 · 0 评论 -
剑指 Offer 24. 反转链表
https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/ [wrong code] /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { public List原创 2021-05-11 19:23:35 · 33 阅读 · 0 评论 -
剑指 Offer 18. 删除链表的节点
https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/ [bug] 1 review by reading 2 null pointer [wrong code] /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) {原创 2021-05-10 21:07:49 · 57 阅读 · 0 评论 -
剑指 Offer 17. 打印从1到最大的n位数
https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof/ [bug] 1 array size 2 shift class Solution { public int[] printNumbers(int n) { int N = Math.pow(10, n); int[] ret = new int[N]; for(int i=1;i<N;i++)原创 2021-05-10 20:58:16 · 38 阅读 · 0 评论 -
剑指 Offer 07. 重建二叉树
https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/ [brainstorm] how to build a tree? build from root. how to cotinue? from root, go its left, right child. one way is to go down level by level. 4 2 1 3 6 5 7 | preorder 1 2 3 4 5 6 7 | inorder 4 /原创 2021-05-07 10:27:34 · 46 阅读 · 0 评论 -
剑指 Offer 04. 二维数组中的查找
剑指 Offer 04. 二维数组中的查找 https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/ *brute force go line by line for each line, use binary O(n^lgn) *can be do better? locate which line binary on that line counter example 1 3 5 4 6 7 8 9 10 *what i原创 2021-05-07 10:12:19 · 40 阅读 · 0 评论 -
剑指 Offer 06. 从尾到头打印链表
[wrong code] /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { public int[] reversePrint(ListNode head) { if(head==null){原创 2021-05-06 23:05:16 · 43 阅读 · 0 评论