Movatterモバイル変換


[0]ホーム

URL:


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

Commit71de8eb

Browse files
committed
Added a solution and updated README
1 parentec8b5a8 commit71de8eb

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
classSolution {
2+
publicintevalRPN(String[]tokens) {
3+
Stack<Integer>stack =newStack<>();
4+
5+
Stringsigns ="+-*/";
6+
7+
for (Stringtoken :tokens) {
8+
if (signs.indexOf(token) != -1) {
9+
intnum1 =stack.pop();
10+
intnum2 =stack.pop();
11+
12+
inttemp =performOperation(num2,num1,token);
13+
14+
stack.push(temp);
15+
}
16+
else {
17+
stack.push(Integer.parseInt(token));
18+
}
19+
}
20+
21+
returnstack.peek();
22+
}
23+
24+
privateintperformOperation(intn1,intn2,Stringoper) {
25+
if (oper.equals("+")) {
26+
returnn1 +n2;
27+
}
28+
elseif (oper.equals("-")) {
29+
returnn1 -n2;
30+
}
31+
elseif (oper.equals("*")) {
32+
returnn1 *n2;
33+
}
34+
else {
35+
returnn1 /n2;
36+
}
37+
}
38+
}

‎README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
#LeetCode-Java-Solutions
2+
Repository to store solutions to various problems in Leetcode practice and weekly contests
3+
4+
[My Leetcode Profile](https://leetcode.com/varunu28/)
25

36
![image](https://cdn-images-1.medium.com/max/1360/1*5qdPLs4x9TuabvQJwu7iuA.png)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp