摘要: 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 阳光明媚的菲越 阅读(21) 评论(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 阳光明媚的菲越 阅读(20) 评论(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 阳光明媚的菲越 阅读(78) 评论(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 阳光明媚的菲越 阅读(28) 评论(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 阳光明媚的菲越 阅读(20) 评论(0) 推荐(0) 编辑
摘要: 这道题就是921的变种,话不多说: public int maxDepth(String s) { int count = 0; int max = 0; for (char c : s.toCharArray()) { if (c == '(') { count++; max = Math.max 阅读全文
posted @ 2022-02-02 03:12 阳光明媚的菲越 阅读(27) 评论(0) 推荐(0) 编辑
摘要: For this problem, if you can remember, always push the index of '(', the problem can be solved easily. The solution is: 1. if meet a '(', push the ind 阅读全文
posted @ 2022-02-02 02:28 阳光明媚的菲越 阅读(25) 评论(0) 推荐(0) 编辑
摘要: 这道题是括号题,这种括号题如果是一种括号,就用一个int做stack就行,但是如果是多种括号,用int就烦琐了,一定要用Stack,下面是我的算法,时间复杂度就是O(n). 我把每类括号的做括号和右括号放在map中,如果是左括号就push到stack,如果是右括号,就pop stack,map中对应 阅读全文
posted @ 2022-02-02 01:11 阳光明媚的菲越 阅读(30) 评论(0) 推荐(0) 编辑