682. Baseball Game
static int wing=[]()
{
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return ;
}(); class Solution
{
public:
int calPoints(vector<string>& ops)
{
int lastvalid=;
int sz=ops.size();
vector<int> sore(sz+,INT_MIN);
for(string &s:ops)
{
if(s[]=='+')
{
sore[lastvalid]=sore[lastvalid-]+sore[lastvalid-];
lastvalid++;
}
else if(s[]=='D')
{
sore[lastvalid]=sore[lastvalid-]*;
lastvalid++;
}
else if(s[]=='C')
lastvalid--;
else
sore[lastvalid++]=stoi(s);
}
return accumulate(sore.begin(),sore.begin()+lastvalid,);
}
};
用栈或者vector都行,string转int可以直接stoi,学到了,妈个腿
682. Baseball Game的更多相关文章
- 【Leetcode_easy】682. Baseball Game
problem 682. Baseball Game solution: 没想到使用vector! class Solution { public: int calPoints(vector<s ...
- 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&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 ...
- 682. Baseball Game 棒球游戏 按字母处理
[抄题]: You're now a baseball game point recorder. Given a list of strings, each string can be one of ...
- [LeetCode] 682. 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 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 使用栈模拟 日期 题目地址:https://leet ...
- 682. Baseball Game (5月28日)
解答(打败98.60%) class Solution { public: int calPoints(vector<string>& ops) { vector<int&g ...
- LeetCode All in One题解汇总(持续更新中...)
突然很想刷刷题,LeetCode是一个不错的选择,忽略了输入输出,更好的突出了算法,省去了不少时间. dalao们发现了任何错误,或是代码无法通过,或是有更好的解法,或是有任何疑问和建议的话,可以在对 ...
- 2017/11/9 Leetcode 日记
2017/11/9 Leetcode 日记 566. Reshape the Matrix In MATLAB, there is a very useful function called 'res ...
随机推荐
- python爬虫相关基础概念
什么是爬虫 爬虫就是通过编写程序模拟浏览器上网,然后让其去互联网上抓取数据的过程. 哪些语言可以实现爬虫 1.php:可以实现爬虫.但是php在实现爬虫中支持多线程和多进程方面做得不好. 2.java ...
- Karma - MVC Framework for Unity3D
Karma is an MVC framework for Unity3D. Because of how Unity is structured, it actually turns out to ...
- ECMAScript6的原型
class Car { constructor(name){ this.name = name; } getName(){ } } class Ferrari extends Car{ constru ...
- jquey中json字符串与json的转换(转)
<!doctype html> <html> <head> <meta charset="utf-8"> <script sr ...
- [leetcode]123. Best Time to Buy and Sell Stock III 最佳炒股时机之三
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- django static 无法正确加载目录下的css
在static->web目录下添加CSS后该css文件一直报404错误,解决问题: 在setting.py文件添加: STATICFILES_DIRS = [ os.path.join(BASE ...
- HTML5拖拽事件笔记
在HTML5的规范中,我们可以通过为元素增加`draggable="true"`来设置此元素是否可以进行拖拽操作,其中图片.链接默认是开启的. 1. 拖拽元素:设置了`dragga ...
- windows7 Cygwin 下安装 YouCompleteMe 插件
原创文章,欢迎指正!转载请注明~ 从上周就开始想在cygwin上安装YouCompleteMe插件,按照GITHUB上的官方教程安装,由于自己的理解失误,一直搞不清是按照在windows上安装还是按照 ...
- python 数据类型 之 利用 dict 模仿 switch语句功能
Python本身并不提供Switch的语法功能,为了能够解决类似switch分支需求的问题,我们可以使用字典代替实现. 解决思路: 利用字典取值的get方法的容错性,处理switch语句中的defau ...
- andorid 手机外部储存
.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android ...