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 ...
随机推荐
- Salesforce LWC学习(七) Navigation & Toast
上一篇我们介绍了针对LWC中常用的LDS的适配的wire service以及@salesforce模块提供的相关的service,其实LWC中还提供其他的好用的service,比如针对导航相关的lig ...
- 金融风控100道面试题:传统银行开发转行互金top3公司并年薪40多万
知乎上有一个50万人看过的问题“为什么自学Python看不进去?”,其实原因很简单,大家缺乏能动手实战的机会. 知识要是死记硬背记在在脑海中,用不了多久就会忘记,只用依靠实战才能让知识落地. 小七这次 ...
- ELKBR部署检测项目日志
ELK filebeat:具有日志收集功能,相比logstash,+filebeat更轻量,占用资源更少,适合客户端使用. redis消息队列选型:Redis 服务器通常都是用作 NoSQL 数据库, ...
- kafka topic消息分配partition规则(Java源码)
我们知道Kafka 的消息通过topic进行分类.topic可以被分为若干个partition来存储消息.消息以追加的方式写入partition,然后以先入先出的顺序读取. 下面是topic和part ...
- android小工具-系统音量管理器
简介:调节系统音量的小工具,能够快捷的调节系统铃声,媒体音乐.闹钟和通话声音.你可能会想,手机自带的音量键还不够快捷吗?还得写个程序?首先,用音量键调音只能调节一种声音,像闹钟这种声音不能直接调.其次 ...
- map转java对象
pom依赖: <dependency> <groupId>commons-beanutils</groupId> <artifactId>commons ...
- Metasploit工具----漏洞利用模块
漏洞利用是指由渗透测试者利用一个系统.应用或者服务中的安全漏洞进行的攻击行为.流行的渗透攻击技术包括缓冲区溢出.Web应用程序攻击,以及利用配置错误等,其中包含攻击者或测试人员针对系统中的漏洞而设计的 ...
- LeetCode 1169. 查询无效交易
题目链接:https://leetcode-cn.com/problems/invalid-transactions/ 如果出现下述两种情况,交易 可能无效: 交易金额超过 ¥1000或者,它和另一个 ...
- C++ const 引用 指针
先简单回忆一下常量的性质: int main() { const int buffSize = 512; buffsize = 512; //× buffSize是常量 } 初始化时: const i ...
- java httpclient跳过https证书验证
httpclien调用skipHttpsUtil得wrapClient方法跳过https证书验证 SkipHttpsUtil skipHttpsUtil=new SkipHttpsUtil(); ...