Merge pull request #2783 from yeahwangz/master
commit1:纠正 problems/1047.删除字符串中的所有相邻重复项.md 中 java版本 注释:将top>0纠正为top>=0 && commit2:纠正 0150.逆波兰表达式求值.md 的c++代码,将第21行代码的int修改为long long, 原因:既然前面考虑到可能数据值大而将int改为了long long,那么最后的RPN运算结果也 可能超过int能表示的范围
This commit is contained in:
commit
d04090f22a
|
|
@ -108,7 +108,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int result = st.top();
|
long long result = st.top();
|
||||||
st.pop(); // 把栈里最后一个元素弹出(其实不弹出也没事)
|
st.pop(); // 把栈里最后一个元素弹出(其实不弹出也没事)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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--;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue