leetcode682
class Solution {
public:
int calPoints(vector<string>& ops) {
stack<int> ST;
int sum = ;
for (auto o : ops)
{
if (o == "C")
{
int n = ST.top();
sum -= n;
ST.pop();
}
else if (o == "D")
{
int n = ST.top() * ;
sum += n;
ST.push(n);
}
else if (o == "+")
{
int t1 = ST.top();
ST.pop();
int t2 = ST.top();
int n = t1 + t2;
sum += n;
ST.push(t1);
ST.push(n);
}
else
{
int n = atoi(o.c_str());
sum += n;
ST.push(n);
}
}
return sum;
}
};
leetcode682的更多相关文章
- [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 ...
- Leetcode682.Baseball Game棒球比赛
你现在是棒球比赛记录员. 给定一个字符串列表,每个字符串可以是以下四种类型之一: 1.整数(一轮的得分):直接表示您在本轮中获得的积分数. 2. "+"(一轮的得分):表示本轮获得 ...
- LeetCode682 棒球比赛
题目描述: 你现在是棒球比赛记录员.给定一个字符串列表,每个字符串可以是以下四种类型之一:1.整数(一轮的得分):直接表示您在本轮中获得的积分数.2. "+"(一轮的得分):表示本 ...
- LeetCode-Stack-Easy
简单题 1. 有效的括号(leetcode-20) 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 1. 左括号必须用相同类型的右括 ...
随机推荐
- CPU高获取其线程ID然后分析
一.具体步骤 shift+p 按照cpu排序 shift+m按照内存排序 1.查看进程下所有线程 top -H -p pid 2.将十进制数换成16进制:print "%x/n" ...
- 转:走近NoSQL数据库的四大家族
在目前的企业IT架构中,系统管理员以及DBA都会考虑使用NoSQL数据库来解决RDBMS所不能解决的问题,特别是互联网行业.传统的关系型数据库主要以表(table)的形式来存储数据,而无法应对非结构化 ...
- Qt DLL总结
(转自:http://qimo601.iteye.com/blog/1397936) QT动态链接库的调用方法,主要包括: 1.显式链接DLL,调用DLL的全局函数,采用Qt的QLibrary方法 2 ...
- LeetCode OJ:Word Search(单词查找)
Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...
- LeetCode OJ:Multiply Strings (字符串乘法)
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- 伪变量foo foober是什么意思
原文: The terms foobar, foo, bar, baz and qux are sometimes used as placeholder names (also referred t ...
- 2017.11.15 Add a parameter –serial <serial no> to the Target field.
1 exe创建快捷方式,并且加后缀 program --serial 50114130 这是Win里面的一种调用说明. Please note that the programming logs ...
- Leetcode 1015. Smallest Integer Divisible by K
思路显然是暴力枚举. 但是两个问题: 1.当1的位数非常大时,模运算很费时间,会超时. 其实每次不用完全用'11111...'来%K,上一次的余数*10+1后再%K就行. 证明: 令f(n)=1111 ...
- 安装使用lynis扫描Linux的安全漏洞
Lynis是Linux平台上的一款安全漏洞扫描工具.它可以扫描系统的安全漏洞.收集系统信息.安装的软件信息.配置问题.没有设置密码的用户和防火墙等等. Lynis是流行可靠的安全扫描工具. 前不久,L ...
- (三)canvas绘制样式
beginPath() 对画线点的一个开始限制 moveTo() 画线的起点,只在开头使用 参数两个x轴,y轴 lineTo() 后续连线 两个参数x轴,y轴 stroke() 连线无填充 fill( ...