LeetCode_682-Baseball Game
给定一个字符串列表,字符串包含整数,’+’,’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的更多相关文章
- Simulation of empirical Bayesian methods (using baseball statistics)
Previously in this series: The beta distribution Empirical Bayes estimation Credible intervals The B ...
- [LeetCode] Baseball Game 棒球游戏
You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 ...
- [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 ...
- (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 ...
- LeetCode 682 Baseball Game 解题报告
题目要求 You're now a baseball game point recorder. Given a list of strings, each string can be one of t ...
- LeetCode - Baseball Game
You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 ...
- [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 ...
- 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 ...
- Programming Assignment 3: Baseball Elimination
编程作业三 作业链接:Baseball Elimination & Checklist 我的代码:BaseballElimination.java 问题简介 这是一个最大流模型的实际应用问题: ...
- 682. Baseball Game 棒球游戏 按字母处理
[抄题]: You're now a baseball game point recorder. Given a list of strings, each string can be one of ...
随机推荐
- 【Offer】[10-1] 【斐波那契数列】
题目描述 思路分析 Java代码 代码链接 题目描述  大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0). 思路分析 递归的思路,会出现很多重复的 ...
- java多线程之ThreadPoolExecutor
ThreadPoolExecutor类 简介 java.uitl.concurrent.ThreadPoolExecutor类是线程池中最核心的一个类,因此如果要透彻地了解Java中的线程池,必须 ...
- Java复习:集合框架(一张图)
最后一个看不见了补充一下: ConcurrentHashMap:是线程安全的(基于lock实现的,同步的时候锁住的不是整个对象,而加了synchronized的是锁住了整个的对象),实现了Map接口, ...
- JAVASSM框架面试题
1.SpringMVC的工作流程? 1. 用户发送请求至前端控制器DispatcherServlet 2. DispatcherServlet收到请求调用HandlerMapping处理器映射器. 3 ...
- python+selenium调用chrome打开网址获取内容
目录 1,安装selenium和配置chromedriver 2,调用chromedriver打开网页获取网页内容 3,模拟登陆百度云 附录(webdriver版本兼容列表) 通过selenium库, ...
- ubuntu修改中文文件夹名字为英文
为了使用起来方便,装了ubuntu中文版,自然在home文件里用户目录的“桌面”.“图片”.“视频”.“音乐”……都是中文的. 很多时候都喜欢在桌面上放一些要操作的文件,Linux里命令行操作又多,难 ...
- java获取电脑mac物理地址
import java.net.InetAddress;import java.net.NetworkInterface;import java.net.SocketException;import ...
- 具有注册、登陆以及后台管理功能的web开发
设计一个带有注册.登陆.后台用户管理的网站 使用(Html+Css+JavaScript+Jsp+Servlet+JDBC+JSTL+EL) 工具:Eclipse(NetBeans).Mysql8.0 ...
- 【Sentinel】sentinel 集成 apollo 最佳实践
[Sentinel]sentinel 集成 apollo 最佳实践 前言 在 sentinel 的控制台设置的规则信息默认都是存在内存当中的.所以无论你是重启了 sentinel 的客户端还是 s ...
- [VB.NET Tips]Try...Catch...End Try的另一种用法
有时在调用一个方法时,会进行异常处理.但是当方法内部出现错误时,无法快速定位到是哪一行代码有问题. 下面介绍一下Try的另一个用法: Try...Catch ex As Exception When ...