摘要: 这道题就是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 阳光明媚的菲越 阅读(26) 评论(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 阳光明媚的菲越 阅读(22) 评论(0) 推荐(0) 编辑
摘要: 这道题是括号题,这种括号题如果是一种括号,就用一个int做stack就行,但是如果是多种括号,用int就烦琐了,一定要用Stack,下面是我的算法,时间复杂度就是O(n). 我把每类括号的做括号和右括号放在map中,如果是左括号就push到stack,如果是右括号,就pop stack,map中对应 阅读全文
posted @ 2022-02-02 01:11 阳光明媚的菲越 阅读(25) 评论(0) 推荐(0) 编辑
摘要: public class Solution { private String[] lessThanTwenty = { "", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven 阅读全文
posted @ 2022-01-28 06:20 阳光明媚的菲越 阅读(20) 评论(0) 推荐(0) 编辑
摘要: To solve this problem, we need two steps: 1. Convert "order" string to a Hashmap, the key is the characor in the "order" string, value is its index. 2 阅读全文
posted @ 2022-01-28 04:54 阳光明媚的菲越 阅读(19) 评论(0) 推荐(0) 编辑
摘要: 这道题是典型的括号题,一般来说,括号题用stack做,但是这道题因为太简单了,连stack都不用, 就用int就好了,时间复杂度O(n)。 public int minAddToMakeValid(String s) { int count = 0; int res = 0; for(int i=0 阅读全文
posted @ 2022-01-28 04:31 阳光明媚的菲越 阅读(18) 评论(0) 推荐(0) 编辑
该文被密码保护。 阅读全文
posted @ 2022-01-26 03:00 阳光明媚的菲越 阅读(0) 评论(0) 推荐(0) 编辑
该文被密码保护。 阅读全文
posted @ 2022-01-25 11:37 阳光明媚的菲越 阅读(2) 评论(0) 推荐(0) 编辑
该文被密码保护。 阅读全文
posted @ 2022-01-25 08:13 阳光明媚的菲越 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 找两组数据的最大数值,可以自顶向下写个递归,把可能重复的部分记录下来,用一个二维数组来存储: class Solution { private Integer[][] dp; private int m, n; public int longestCommonSubsequence(String t 阅读全文
posted @ 2022-01-25 07:40 阳光明媚的菲越 阅读(25) 评论(0) 推荐(0) 编辑