top面试150.逆波兰表达式求值

题目描述:

top面试150.逆波兰表达式求值_第1张图片

思路:遍历整个数组,依次将遇到数字存入栈,遇到符号经过运算后存入栈,可用数组模拟栈。

class Solution {
public:
    int evalRPN(vector& tokens) {
		vector numStack (tokens.size()/2 + 1, 0);
		int index = 0;
        for(int i=0;i

 

你可能感兴趣的:(leetcode刷题)