摘要: First I wrote a bruteforce solution, but it didn't pass because of too many calls, the time complexity is O(m*n): public int leftMostColumnWithOne(Bin 阅读全文
posted @ 2022-02-03 03:50 阳光明媚的菲越 阅读(30) 评论(0) 推荐(0) 编辑
摘要: This problem can be solved by sliding window: 1. firstly the right point, j, start to move, if it meet a zero, the zeroNum++, which means, we convert 阅读全文
posted @ 2022-02-03 03:03 阳光明媚的菲越 阅读(22) 评论(0) 推荐(0) 编辑
摘要: This is the typical DP problem, the time complexity is O(n2), Where n is the length of string s. This is due to the fact that we try to find result fo 阅读全文
posted @ 2022-02-03 00:47 阳光明媚的菲越 阅读(16) 评论(0) 推荐(0) 编辑
摘要: To solve the shortest path problem, of course, you need to think of the BFS: public int shortestPathBinaryMatrix(int[][] grid) { int[][] dirs = {{-1, 阅读全文
posted @ 2022-02-02 14:25 阳光明媚的菲越 阅读(20) 评论(0) 推荐(0) 编辑
摘要: Don't think about a lot, this is a very easy problem, time complexity is O(m*n) public boolean isToeplitzMatrix(int[][] matrix) { if (matrix == null | 阅读全文
posted @ 2022-02-02 14:18 阳光明媚的菲越 阅读(19) 评论(0) 推荐(0) 编辑
摘要: For the solution of this problem, we should be able to tell that it need a binary search. The left value is the maxmum weight in the weight list, beca 阅读全文
posted @ 2022-02-02 13:55 阳光明媚的菲越 阅读(17) 评论(0) 推荐(0) 编辑
摘要: My solution for this problem is using two stacks, it's very easy to understand: public boolean checkValidString(String s) { Stack<Integer> stars = new 阅读全文
posted @ 2022-02-02 11:19 阳光明媚的菲越 阅读(75) 评论(0) 推荐(0) 编辑
摘要: This problem is a typical backtracking solution problem, we need a recursive method as helper, the following is my first solution, which is not very g 阅读全文
posted @ 2022-02-02 08:21 阳光明媚的菲越 阅读(25) 评论(0) 推荐(0) 编辑
该文被密码保护。 阅读全文
posted @ 2022-02-02 06:56 阳光明媚的菲越 阅读(0) 评论(0) 推荐(0) 编辑
摘要: Parentheses的题,首先想到stack,思路如下: 1. If get a left parentheses, if the stack size is odd number, that means, one right parentheses is missing, so result p 阅读全文
posted @ 2022-02-02 04:33 阳光明媚的菲越 阅读(19) 评论(0) 推荐(0) 编辑