problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::baseball_game::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static int calPoints (vector< string > &ops)
 

详细描述

在文件 leetcode.h1918 行定义.

成员函数说明

◆ calPoints()

int leetcode::baseball_game::Solution::calPoints ( vector< string > &  ops)
static

在文件 leetcode.cpp5029 行定义.

5029 {
5030 vector<int> stk;
5031 for(const string &op: ops) {
5032 if(op == "+") {
5033 const int score1 = stk.back();
5034 const int score2 = *(stk.rbegin() + 1);
5035 stk.push_back(score1 + score2);
5036 } else if(op == "D") {
5037 stk.push_back(2 * stk.back());
5038 } else if(op == "C") {
5039 stk.pop_back();
5040 } else {
5041 stringstream ss;
5042 ss << op;
5043 int score;
5044 ss >> score;
5045 stk.push_back(score);
5046 }
5047 }
5048 int ans = 0;
5049 for(const auto score: stk) {
5050 ans += score;
5051 }
5052 return ans;
5053 }

被这些函数引用 leetcode::baseball_game::TEST().


该类的文档由以下文件生成: