当前位置:网站首页>20220608 other: evaluation of inverse Polish expression
20220608 other: evaluation of inverse Polish expression
2022-07-03 10:11:00 【Seeyouagain】
Title Description : according to Reverse Polish notation , Find the value of the expression . Valid operators include +、-、*、/ . Each operand can be an integer , It can also be another inverse Polish expression . Be careful The division between two integers retains only the integer part .
coded :
public int evalRPN(String[] tokens) {
Stack<Integer> stack = new Stack<>();
for (String token : tokens) {
if (noDigit(token)) {
Integer b = stack.pop();
Integer a = stack.pop();
stack.push(calc(a, b, token));
continue;
}
stack.push(Integer.parseInt(token));
}
return stack.peek();
}
private boolean noDigit(String s) {
return "+".equals(s) || "-".equals(s) || "*".equals(s) || "/".equals(s);
}
private int calc(int a, int b, String c) {
switch (c) {
case "+":
return a + b;
case "-":
return a - b;
case "*":
return a * b;
case "/":
return a / b;
default:
return 0;
}
}
边栏推荐
- Leetcode 300 longest ascending subsequence
- Tensorflow2.0 save model
- CV learning notes convolutional neural network
- My notes on the development of intelligent charging pile (III): overview of the overall design of the system software
- Mise en œuvre d'OpenCV + dlib pour changer le visage de Mona Lisa
- Anaconda安装包 报错packagesNotFoundError: The following packages are not available from current channels:
- 20220603数学:Pow(x,n)
- 2021-11-11 standard thread library
- My 4G smart charging pile gateway design and development related articles
- 20220610其他:任务调度器
猜你喜欢

LeetCode - 673. Number of longest increasing subsequences

Opencv notes 20 PCA

Opencv gray histogram, histogram specification

Leetcode - 1670 design front, middle and rear queues (Design - two double ended queues)

openCV+dlib实现给蒙娜丽莎换脸

Deep learning by Pytorch

Leetcode-112:路径总和

Dictionary tree prefix tree trie

CV learning notes - deep learning

LeetCode - 508. Sum of subtree elements with the most occurrences (traversal of binary tree)
随机推荐
Leetcode-112: path sum
On the problem of reference assignment to reference
20220609其他:多数元素
3.1 Monte Carlo Methods & case study: Blackjack of on-Policy Evaluation
Leetcode - 1670 design front, middle and rear queues (Design - two double ended queues)
Leetcode - 895 maximum frequency stack (Design - hash table + priority queue hash table + stack)*
Screen display of charging pile design -- led driver ta6932
Opencv feature extraction sift
QT is a method of batch modifying the style of a certain type of control after naming the control
20220605数学:两数相除
4G module board level control interface designed by charging pile
LeetCode - 5 最长回文子串
Yocto Technology Sharing Phase 4: Custom add package support
Pycharm cannot import custom package
The data read by pandas is saved to the MySQL database
『快速入门electron』之实现窗口拖拽
CV learning notes alexnet
yocto 技术分享第四期:自定义增加软件包支持
ADS simulation design of class AB RF power amplifier
Deep learning by Pytorch