-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
#32 动态规划: 最长有效括号对长度问题 #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议增加修改readme,在readme中加入这道题目的链接, 包括中英文
2. s的前**1**个子字符串的最长有效括号对长度为0, | ||
s的前**2**个子字符串的最长有效括号对长度也为0, | ||
这个时候我们可以得出结论: 最长有效的括号对不可能以'('结尾; | ||
3. 当i等于3时, 我们可以看出dp(2)为0, dp(3)=2, 因为第2个字符和第3个字符是配对的, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里dp(2)为0么
|
||
## 扩展 | ||
|
||
1. 如果判断的不仅仅只有(和), 还有[, ], {和}, 改怎么办? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
字符左右建议加引号, 比如"[", "]"
改怎么办 改为 “该怎么办”
## 扩展 | ||
|
||
1. 如果判断的不仅仅只有(和), 还有[, ], {和}, 改怎么办? | ||
2. 如果输出的不是长度, 而是最长有效括号对的字符串, 改怎么办? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改怎么办 改为 “该怎么办”
这个时候我们可以得出结论: 最长有效的括号对不可能以'('结尾; | ||
3. 当i等于3时, 我们可以看出dp(2)为0, dp(3)=2, 因为第2个字符和第3个字符是配对的, | ||
当i等于4时, dp(i-1)为2, dp(4)为4, 我们配对的是第1个字符和第4个字符, | ||
因此, 我们可以得出结论: 如果第**i**个字符和第**i-1-dp(i-1)**个字符是配对的, 则dp(i) = dp(i-1) + 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 4 5 的描述有点啰嗦。 建议说出思路即可,最好配个图
c289155
to
387d74b
Compare
No description provided.