给定一个字符串列表,字符串包含整数,’+’,’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. python实现持久化存储,操作表格,时间戳

    import xlrd,xlwt,pickle,time,datetime book = xlrd.open_workbook("练习.xlsx") sheet1 = book.s ...

  2. Tomcat原理系列之六:详解socket如何封装成request(上)

    目录 参与者 总结 @(详解socket如何封装成request) 看源码虽然不能马上提升你的编码水平.但能让你更好的理解编程. 因为我们tomcat多是以NIO形式处理请求,所以本系列讲的都是NIO ...

  3. ElasticSearch常见经典面试题

    1.为什么要使用Elasticsearch? ​ 因为在我们商城中的数据,将来会非常多,所以采用以往的模糊查询,模糊查询前置配置,会放弃索引,导致商品查询是全表扫面,在百万级别的数据库中,效率非常低下 ...

  4. Fortify安全漏洞一般处理方法

    前段时间公司又一轮安全审查,要求对各项目进行安全扫描,排查漏洞并修复,手上有几个历史项目,要求在限定的时间内全部修复并提交安全报告,也不清楚之前是如何做的漏洞修复,这次使用工具扫描出来平均每个项目都还 ...

  5. java架构之路-(11)JVM的对象和堆

    上次博客,我们说了jvm运行时的内存模型,堆,栈,程序计数器,元空间和本地方法栈.我们主要说了堆和栈,栈的流程大致也说了一遍,同时我们知道堆是用来存对象的,分别年轻代和老年代.但是具体的堆是怎么来存放 ...

  6. tarjan缩点(洛谷P387)

    此题解部分借鉴于九野的博客 题目分析 给定一个 \(n\) 个点 \(m\) 条边有向图,每个点有一个权值,求一条路径,使路径经过的点权值之和最大.你只需要求出这个权值和. 允许多次经过一条边或者一个 ...

  7. puttdy连接服务器报错No supported authentication methods available (server sent:publickey,gassapi-keyex,gassapi-with-mic)

    No supported authentication methods available (server sent:publickey,gassapi-keyex,gassapi-with-mic) ...

  8. FreeSql (六)批量插入数据

    var connstr = "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;" + "Initia ...

  9. 安装Harbor管理镜像服务

    Harbor是什么? 还记得Docker Registry么?它是Docker官方提供的镜像仓库,简单易用,一键就可以部署.使用. 虽然看起来不错,但是Registry有些问题需要解决: 没有图形界面 ...

  10. Winforn中导入Excel并显示然后获取多选框选中的内容

    场景 使用NPOI导入Excel并赋值给DataTable,然后显示在DataGrdView上,并且添加多选框,然后获取选中行的内容. Winform中使用NPOI实现Excel导入并赋值给DataT ...