Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from youngyangyang04:master #104

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
pull merged 8 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
Oct 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update 0150.逆波兰表达式求值.md
力扣修改了后端测试数据
  • Loading branch information
youngyangyang04 authored Oct 2, 2022
commit b0ec03922ea2081f0aa72e7fccf8a322aa9a9efb
11 changes: 4 additions & 7 deletions problems/0150.逆波兰表达式求值.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ C++代码如下:
class Solution {
public:
int evalRPN(vector<string>& tokens) {
// 考虑到第20个样例使用int会溢出
// 此处使用long long来存储number
// 在最后用int()强行转换成int输出

// 力扣修改了后台测试数据,需要用longlong
stack<long long> st;
for (int i = 0; i < tokens.size(); i++) {
if (tokens[i] == "+" || tokens[i] == "-" || tokens[i] == "*" || tokens[i] == "/") {
Expand All @@ -105,13 +102,13 @@ public:
if (tokens[i] == "*") st.push(num2 * num1);
if (tokens[i] == "/") st.push(num2 / num1);
} else {
st.push(atoll(tokens[i].c_str()));
st.push(stoll(tokens[i]));
}
}

long long result = st.top();
int result = st.top();
st.pop(); // 把栈里最后一个元素弹出(其实不弹出也没事)
return int(result);
return result;
}
};

Expand Down

AltStyle によって変換されたページ (->オリジナル) /