Skip to content

#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

Merged
merged 1 commit into from
Jun 4, 2019

Conversation

winnochan
Copy link
Contributor

No description provided.

Copy link
Owner

@azl397985856 azl397985856 left a 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个字符是配对的,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里dp(2)为0么


## 扩展

1. 如果判断的不仅仅只有(和), 还有[, ], {和}, 改怎么办?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

字符左右建议加引号, 比如"[", "]"

改怎么办 改为 “该怎么办”

## 扩展

1. 如果判断的不仅仅只有(和), 还有[, ], {和}, 改怎么办?
2. 如果输出的不是长度, 而是最长有效括号对的字符串, 改怎么办?
Copy link
Owner

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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 4 5 的描述有点啰嗦。 建议说出思路即可,最好配个图

@winnochan winnochan force-pushed the master branch 6 times, most recently from c289155 to 387d74b Compare June 4, 2019 13:42
@azl397985856 azl397985856 merged commit e0d8b2a into azl397985856:master Jun 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants