给定一个字符串列表,字符串包含整数,’+’,’D’,’C’,整数代表一个分数,’+’代表后两个有效分数的和,’D’代表后一个有效分数的两倍,’C’代表删除后一个有效的分数值,最后求所有有效分数的和。
例子:
输入[“5”,”2”,”C”,”D”,”+”],输出30。2为无效的数,’D’是5*2,’+’是5*2+5,5+0+10+(10+5)= 30

class Solution {
public:
int calPoints(vector<string>& ops) {
stack<int> stackRes;
for(int i=; i<ops.size(); i++) {
if(ops[i][] == 'C') {
if(!stackRes.empty()) {
stackRes.pop();
}
}
else if(ops[i][] == 'D') {
if(!stackRes.empty()) {
int nNum = stackRes.top();
nNum *= ;
stackRes.push(nNum);
}
}
else if(ops[i][] == '+') {
if(!stackRes.empty()) {
int nNum = stackRes.top();
stackRes.pop();
int nSum = nNum + stackRes.top();
stackRes.push(nNum);
stackRes.push(nSum);
}
}
else {
stackRes.push(atoi(ops[i].c_str()));
}
}
int nResRum = ;
while(!stackRes.empty()) {
nResRum += stackRes.top();
stackRes.pop();
}
return nResRum;
}
};

可关注公众号了解更多的面试技巧

LeetCode_682-Baseball Game的更多相关文章

  1. Simulation of empirical Bayesian methods (using baseball statistics)

    Previously in this series: The beta distribution Empirical Bayes estimation Credible intervals The B ...

  2. [LeetCode] Baseball Game 棒球游戏

    You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 ...

  3. [Swift]LeetCode682. 棒球比赛 | Baseball Game

    You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 ...

  4. (string stoi 栈)leetcode682. Baseball Game

    You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 ...

  5. LeetCode 682 Baseball Game 解题报告

    题目要求 You're now a baseball game point recorder. Given a list of strings, each string can be one of t ...

  6. LeetCode - Baseball Game

    You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 ...

  7. [LeetCode&Python] Problem 682. Baseball Game

    You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 ...

  8. Stack-682. Baseball Game

    You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 ...

  9. Programming Assignment 3: Baseball Elimination

    编程作业三 作业链接:Baseball Elimination & Checklist 我的代码:BaseballElimination.java 问题简介 这是一个最大流模型的实际应用问题: ...

  10. 682. Baseball Game 棒球游戏 按字母处理

    [抄题]: You're now a baseball game point recorder. Given a list of strings, each string can be one of ...

随机推荐

  1. 小米下拉框jQuery实现

    <div class="daohanglan"> <div class="dh">小米手机 <--多个自己定义--> < ...

  2. Optional和Stream的map与flatMap

    Optional的map和flatMap Optional存在map和flatMap方法.map源码如下 public<U> Optional<U> map(Function& ...

  3. Python二元操作符

    def quiz_message(grade): outcome = 'failed' if grade<50 else 'passid' print ('grade', grade, 'out ...

  4. spring boot使用guava缓存

    1.pom中插入依赖: <!--guava缓存cache--> <dependency> <groupId>com.google.guava</groupId ...

  5. Django之FBV和CBV的用法

    FBV FBV,即 func base views,函数视图,在视图里使用函数处理请求. 以用户注册代码为例, 使用两个函数完成注册 初级注册代码 def register(request): &qu ...

  6. 1512: [POI2006]Pro-Professor Szu

    首先把边反向, 问题转化成求从主建筑楼走向各个点的方案数. 然后缩点,块中的方案数可以直接算. 设f[i]表示走到第i个点的方案数.显然f[i]=∑f[j](存在newedge(j,i))初始时,f[ ...

  7. day01小结

    Java特点 1,面向对象的(write once,run anywhere) 2,跨平台的 ,,,,,, Java体系结构 JavaSE,JavaEE,JavaME,Java Card 对JDK,J ...

  8. 一文搞懂 deconvolution、transposed convolution、sub-­pixel or fractional convolution

    目录 写在前面 什么是deconvolution convolution过程 transposed convolution过程 transposed convolution的计算 整除的情况 不整除的 ...

  9. Nginx 日志文件 access_log详解及日志分割

    Module ngx_http_log_module nginx 日志相关指令主要有两条, 一条是log_format,用来设置日志格式,另外一条是access_log,用来指定日志文件的存放路径.格 ...

  10. C# 10分钟入门基于WebOffice实现在线编辑文档,实时保存到服务器(所有office,兼容WPS)

    今天,他来了(weboffice在线编辑文档). 上次写了一个在线预览的博,当然,效果并不是太理想,但是紧急解决了当时的问题. 后来,小编重新查找资料,求助大牛,终于使用新的方式替换了之前的low方法 ...