【leetcode】150. 逆波兰表达式求值
int evalRPN(char ** tokens, int tokensSize){ int stack[5000], i, top=0; for (i=0; i<tokensSize; i++){ if ( isdigit(tokens[i][0]) || strlen(tokens[i])>1 ){ stack[top++]=atoi(tokens[i]); } else{ if (tokens[i][0] == '+') stack[top-2]=stack[top-2]+stack[top-1]; else if(tokens[i][0] == '-') stack[top-2]=stack[top-2]-stack[top-1]; else if(tokens[i][0] == '*') stack[top-2]=stack[top-2]*stack[top-1]; else if(tokens[i][0] == '/') stack[top-2]=stack[top-2]/stack[top-1]; top--; } } return stack[top-1]; }