![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/8b9f00571965117b733780e625832dca.png)
class Solution {
public:
int evalRPN(vector<string>& tokens) {
stack<int> st;
for (int i = 0; i < tokens.size(); i++) {
if (tokens[i] == "+" || tokens[i] == "-" || tokens[i] == "*" || tokens[i] == "/") {
int num1 = st.top();
st.pop();
int num2 = st.top();
st.pop();
if (tokens[i] == "+") st.push(num2 + num1);
if (tokens[i] == "-") st.push(num2 - num1);
if (tokens[i] == "*") st.push(num2 * num1);
if (tokens[i] == "/") st.push(num2 / num1);
} else {
st.push(stoi(tokens[i]));
}
}
int result = st.top();
st.pop();
return result;
}
};
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/81fc6a822ef0ec8ad9f2db536f795577.png)
class Solution {
public:
string simplifyPath(string path) {
path += "/";
stack<string> st;
string dir;
for (auto c : path) {
if (c == '/') {
if (dir == ".." && !st.empty()) {
st.pop();
}
else if (dir != ".." && dir != "." && !dir.empty()) {
st.push(dir);
}
dir.clear();
}
else {
dir += c;
}
}
string result;
while (!st.empty()) {
string s = st.top();
st.pop();
result = "/" + s + result;
}
if(result.empty()) result = "/";
return result;
}
};