纠正 problems/1047.删除字符串中的所有相邻重复项.md 中java版本相关注释:将top>0纠正为top>=0

This commit is contained in:
01geek
2024-10-09 16:28:31 +08:00
parent aab47d3a3d
commit d33c76e74a

View File

@ -164,7 +164,7 @@ class Solution {
int top = -1; int top = -1;
for (int i = 0; i < s.length(); i++) { for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i); char c = s.charAt(i);
// 当 top > 0,即栈中有字符时,当前字符如果和栈中字符相等,弹出栈顶字符,同时 top-- // 当 top >= 0,即栈中有字符时,当前字符如果和栈中字符相等,弹出栈顶字符,同时 top--
if (top >= 0 && res.charAt(top) == c) { if (top >= 0 && res.charAt(top) == c) {
res.deleteCharAt(top); res.deleteCharAt(top);
top--; top--;