自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(68)
  • 收藏
  • 关注

原创 lintcode 5 · Kth Largest Element

https://www.lintcode.com/problem/5/?_from=cat[]what is the bug?[code]public class Solution { /** * @param k: An integer * @param nums: An array * @return: the Kth largest element */ public int kthLargestElement(int k, int[]

2021-10-15 23:56:41 96

原创 lint 463 · Sort Integers

https://www.lintcode.com/problem/463/?_from=cat[]what is bug?[code]public class Solution { /** * @param A: an integer array * @return: nothing */ public void sortIntegers(int[] A) { // write your code here List&l

2021-10-12 16:46:44 110

原创 lintcode 53 · Reverse Words in a String

https://www.lintcode.com/problem/53/?_from=cat[]how many bugs?[code]public class Solution { /* * @param s: A string * @return: A string */ public String reverseWords(String s) { // write your code here if(s==null

2021-10-12 12:38:38 93

原创 lintcode 13 · Implement strStr()

https://www.lintcode.com/problem/13/?_from=cat[]is code correct?[code]public class Solution { /** * @param source: * @param target: * @return: return the index */ public int strStr(String source, String target) { /

2021-10-12 12:32:06 85

原创 lintcode 521 · Remove Duplicate Numbers in Array

https://www.lintcode.com/problem/521/?_from=cat[bug]what is bug?[code]public class Solution { /** * @param nums: an array of integers * @return: the number of unique integers */ public int deduplication(int[] nums) { // w

2021-10-12 12:27:06 61

原创 lint 1900

https://www.lintcode.com/problem/1900/description// 1 see number & char pair as a whole// 2 locate number, as number string has left, right bound, two pointer here// 3 use top down thinking style, use but NOT implement isDigit(), toNum()// 4 after

2021-10-10 16:53:53 46

原创 lc347 347. Top K Frequent Elements

https://leetcode-cn.com/problems/top-k-frequent-elements/[brainstorm]1 top k freq item, so there is order here.2 instead of N item, only K item, sort vs heap3 sort on count, but return number, how to get number by count?[bug]for(int i=0;i<heap.siz

2021-09-18 20:14:17 67

原创 lc128 128. Longest Consecutive Sequence

https://leetcode-cn.com/problems/longest-consecutive-sequence/e.g. 4 1 3 24 - 3|1 -2[brainstorm]1 union find, set grow bigger. finally, find biggest set size.2 while seeing 3,add 3 to {4}, become {3,4}3 seeing 2add 2 to {1} and {3,4}4 how to l

2021-09-17 16:04:03 98

原创 lc146 146. LRU Cache

https://leetcode-cn.com/problems/lru-cache/[brainstorm]1 map structure for key, value pair.2 remove least recent used, meaning earliest element, use list.list keep item order.3 while update/visit element, timestamp change. what we should do?remove t

2021-09-17 14:54:21 87

原创 lc35 35. Search Insert Position

https://leetcode-cn.com/problems/search-insert-position/[cost]35min[brainstorm]1 by casein betweenleft to index-0right to index-n-12 in betweenas sorted, use binary search.binary search is essentially condense interval.however, does target must

2021-09-16 16:00:15 55

原创 lc34 Find First and Last Position of Element in Sorted Array

https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/[brainstorm] this solution fail in 35min, fail on corner case1 use binary2 find last 8, say target=83 find first 8,then findLast, findFirst be 2 methods, can we j

2021-09-16 14:03:38 55

原创 08.09 面试题 08.09. Bracket LCCI

https://leetcode-cn.com/problems/bracket-lcci/[brainstorm]0/1 -1/\0 2/\ /-1 1 1 31 brute force2 ((()))see it as 1232103 brute force, get list of number string, then transform number string to () string. is it good idea?4 under some con

2021-09-15 21:04:01 59

原创 面试题 08.11. Coin LCCI

https://leetcode-cn.com/problems/coin-lcci/[brainstorm]1 n<0, what is return value?2 n=0, is it corner case to be handled? what is return value?3 dynamic programming, general case,[brainstorm]1 if n<0, cut branch, as solution does NOT exist2 i

2021-09-15 20:52:58 48

原创 面试题 04.03. List of Depth LCCI

https://leetcode-cn.com/problems/list-of-depth-lcci/[time] 25min[brainstorm]1 node in linked list is in same level, consider bfs.2 treenode is in tree structure as input, listnode is in list structure as outputso need to transform treenode to listnode

2021-09-14 19:49:14 41

原创 面试题 02.05. Sum Lists LCCI

https://leetcode-cn.com/problems/sum-lists-lcci/[brainstorm]1 list to num2 num to list[bug]1 cannot pass corner case[code]/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int

2021-09-14 17:42:44 54

原创 lintcode 1116 · Exclusive Time of Functions

https://www.lintcode.com/problem/1116/[brainstorm]1 split log into id, start/end, timestamp2 start log, push into stack3 end log, pop stack topaccumulate time by two entry by minus[question]1 what is wrong for above idea?2 what question should be a

2021-09-10 17:53:56 95

原创 lintcode 1872 · Minimum Cost to Connect Sticks

https://www.lintcode.com/problem/1872/description[brainstorm]1 go through two given cases2 see patternsum up smallest and second smallest,repeat the same calculation.3 use listinsert sum into list cost O(n)say n number, then O(n^2), not good.say

2021-09-10 16:24:57 63

原创 lintcode 451

https://www.lintcode.com/problem/451/[cost]30 min[brainstorm]1 decouple corner case and general case handling.2 when moving to next two nodes, what case should be considered?3 how to keep head as return value?[desc]1 handle corner cases.2 handle g

2021-09-10 14:57:22 64

原创 lc98 98. Validate Binary Search Tree

https://leetcode-cn.com/problems/validate-binary-search-tree/submissions//** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this

2021-09-09 19:43:21 71

原创 98. Validate Binary Search Tree

https://leetcode-cn.com/problems/validate-binary-search-tree/[bug]/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val =

2021-06-28 21:08:36 49

原创 34. Find First and Last Position of Element in Sorted Array

https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/[bug]class Solution { public int[] searchRange(int[] nums, int target) { int[] notFound = new int[]{-1, -1}; if(nums.length==0){ ret

2021-06-28 17:59:43 68

原创 278. First Bad Version

https://leetcode-cn.com/problems/first-bad-version/[bug]/* The isBadVersion API is defined in the parent class VersionControl. boolean isBadVersion(int version); */public class Solution extends VersionControl { public int firstBadVersion(int

2021-06-28 17:02:15 42

原创 1915. Number of Wonderful Substrings

https://leetcode-cn.com/problems/number-of-wonderful-substrings/[bug]class Solution { public long wonderfulSubstrings(String word) { int n = word.length(); int[][] dp = new int[n][n]; for(int i=0;i<n;i++){ char

2021-06-28 12:36:45 151

原创 5790. Minimum Absolute Difference Queries

Minimum Absolute Difference Queries 显示英文描述https://leetcode-cn.com/contest/weekly-contest-246/problems/minimum-absolute-difference-queries/The minimum absolute difference of an array a is defined as the minimum value of |a[i] - a[j]|, where 0 <= i &l.

2021-06-20 15:43:51 139

原创 529. Minesweeper

https://leetcode-cn.com/problems/minesweeper/[bug]class Solution { char[][] upd; char[][] board; int w, h; int[][] dirs = { {-1,-1}, {-1,0}, {-1,1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}

2021-06-18 16:52:28 73

原创 lc332 reconstruct itinarary

https://leetcode-cn.com/problems/reconstruct-itinerary/[bug]class Solution { Map<String, List<String>> adj = new HashMap<>(); public List<String> findItinerary(List<List<String>> tickets) { int n

2021-06-18 15:41:30 67

原创 200. Number of Islands [dfs]

https://leetcode-cn.com/problems/number-of-islands/submissions/[bug]class Solution { char[][] grid; int w, h; boolean[][] visited; int[][] dirs = {{-1,0}, {1,0}, {0,-1}, {0,1}}; public int numIslands(char[][] grid) { th

2021-06-18 14:45:32 42

原创 200. Number of Islands [union find]

https://leetcode-cn.com/problems/number-of-islands/[bug]class Solution { char[][] grid; int w, h; int[][] dirs = {{-1,0}, {1,0}, {0,-1}, {0,1}}; Map<Integer, Integer> map = new HashMap<>(); public int numIslands(char[][]

2021-06-18 13:54:55 137

原创 47. Permutations II

https://leetcode-cn.com/problems/permutations-ii/[bug summary]1 array index vs array element[bug]class Solution { int[] nums; int n; boolean used[]; public List<List<Integer>> permuteUnique(int[] nums) { this.nums

2021-06-17 14:38:07 54

原创 lc490

https://xiaoguan.gitbooks.io/leetcode/content/LeetCode/490-the-maze-medium.html[algorithm]1 what is graph? what is edge? what is node?2 write dfs pseudo3 move() method, what is relevant to this move, make it as param.on high level, use move() as block

2021-06-17 11:47:10 77

原创 207. Course Schedule

https://leetcode-cn.com/problems/course-schedule/why this algorithm is wrong?[algorithm]0 globally have visited node list, keep correct node access order1 pick one node, do traversal like bfs/dfskeep accessed node in a list2 add the previous traver

2021-06-16 17:52:08 42

原创 面试题 16.26. Calculator LCCI

https://leetcode-cn.com/problems/calculator-lcci/algorithm 10mincoding 35mindebug 15min[bug]1 first sign2 last number[buggy code]class Solution { public int calculate(String s) { String str = s.trim(); int n = str.

2021-06-11 20:53:02 51

原创 面试题 16.11. Diving Board LCCI

https://leetcode-cn.com/problems/diving-board-lcci/[bug]class Solution { public int[] divingBoard(int shorter, int longer, int k) { int[] ret = new int[k+1]; int i = 0; int k1 = k; int k2 = 0; while(i<k+1){

2021-06-10 20:21:15 60

原创 今天看continous delivery看到extreme programming

今天看continous delivery看到extreme programming,感觉基本的principle其实和refactoring,和你以前说过的tdd都差不多。就是unit test,然后小步开发,快速迭代啊,频繁测试啊heuristic is to suffer pain early.divided into small parts, naturally complex is small as well.因为有了unit test,就可以在改动的时候 频繁的测试,那就release

2021-06-06 13:50:06 82 1

原创 面试题 03.06. Animal Shelter LCCI

https://leetcode-cn.com/problems/animal-shelter-lcci/[bug]class AnimalShelf { int cnt; List<int[]> cats; //[0] number, [1] id List<int[]> dogs; public AnimalShelf() { cats = new ArrayList<>(); dogs =

2021-06-03 13:52:37 65

原创 面试题 16.17. Contiguous Sequence LCCI

[bug]class Solution { public int maxSubArray(int[] nums) { return recur(nums, 0, nums.length-1); } int recur(int[] nums, int l, int r){ if(l==r){ return nums[l]; } int mid = (l+r)/2;

2021-06-01 18:05:37 63

原创 面试题 17.12. BiNode LCCI

[bug]/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { public TreeNode convertBiNode(TreeNode root) {

2021-06-01 17:22:05 38

原创 面试题 08.06. Hanota LCCI

[bug]class Solution { public void hanota(List<Integer> A, List<Integer> B, List<Integer> C) { int n = A.size(); f(n, A, B, C); } void f(int n, List A, List B, List C){ if(n==1){ C.add(A.

2021-05-30 16:10:35 54

原创 面试题 02.01. Remove Duplicate Node LCCI

[bug][failure case] 1 2 3 3 2 1/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public ListNode removeDuplicateNodes(ListNode hea.

2021-05-30 14:33:30 122

原创 31. Next Permutation

[brainstorm]1 find increase pair, swap the pair.the left number should be as close to the right boundary as possible.e.g.2 32 0 0 32 5 4 36 8 9 72 see more cases by full permutatione.g.1 2 31 3 22 1 33 1 23 2 1find some exceptional case,1 3

2021-05-30 11:56:05 131

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除