682. Baseball Game (5月28日)
解答(打败98.60%)
class Solution {
public:
int calPoints(vector<string>& ops) {
vector<int> v;
int sum=0;
for(auto it=ops.begin();it!=ops.end();++it){
if(*it=="+"){
auto last=v.rbegin();
auto second=++v.rbegin();
int num=(*last)+(*second);
v.push_back(num);
}
else if(*it=="D"){
auto last=v.rbegin();
int num=*last;
v.push_back(num*2);
}
else if(*it=="C"){
v.pop_back();
}
else{
int num=stoi(*it);
v.push_back(num);
}
}
for(auto it=v.begin();it!=v.end();++it){
sum += *it;
}
return sum;
}
};
笔记
- 拿到最后元素有俩种方法
vector<int> v;
1. int last=(*v.rbegin());
2. int last=v.back();
问题
vector<int> v;
1
auto last = v.rbegin();
auto second = ++v.rbegin();
2
auto last = v.rbegin();
auto second = ++last;
为什么第一种就能拿到倒数第二个元素?
682. Baseball Game (5月28日)的更多相关文章
- 2016年12月28日 星期三 --出埃及记 Exodus 21:23
2016年12月28日 星期三 --出埃及记 Exodus 21:23 But if there is serious injury, you are to take life for life,若有 ...
- 无插件的大模型浏览器Autodesk Viewer开发培训-武汉-2014年8月28日 9:00 – 12:00
武汉附近的同学们有福了,这是全球第一次关于Autodesk viewer的教室培训. :) 你可能已经在各种场合听过或看过Autodesk最新推出的大模型浏览器,这是无需插件的浏览器模型,支持几十种数 ...
- 2015年12月28日 Java基础系列(六)流
2015年12月28日 Java基础系列(六)流2015年12月28日 Java基础系列(六)流2015年12月28日 Java基础系列(六)流
- 2016年11月28日 星期一 --出埃及记 Exodus 20:19
2016年11月28日 星期一 --出埃及记 Exodus 20:19 and said to Moses, "Speak to us yourself and we will listen ...
- 2016年10月28日 星期五 --出埃及记 Exodus 19:13
2016年10月28日 星期五 --出埃及记 Exodus 19:13 He shall surely be stoned or shot with arrows; not a hand is to ...
- 2016年6月28日 星期二 --出埃及记 Exodus 14:25
2016年6月28日 星期二 --出埃及记 Exodus 14:25 He made the wheels of their chariots come off so that they had di ...
- 跨界!Omi 发布多端统一框架 Omip 打通小程序与 Web 腾讯开源 2月28日
https://mp.weixin.qq.com/s/z5qm-2bHk_BCJAwaodrMIg 跨界!Omi 发布多端统一框架 Omip 打通小程序与 Web 腾讯开源 2月28日
- 【NEWS】 ADempiere发布ADempiere 3.8.0路线图【2013年7月28日】
发布源:http://osssme.org/cms/?q=node/17 本以为ADempiere”已死“,但是看到ADempiere的WIKI上大概在从5月28日开始添加WIKI以来,经过多次更新后 ...
- 优步UBER司机全国各地奖励政策汇总 (3月28日-4月3日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 全国Uber优步司机奖励政策 (12月28日-1月3日)
本周已经公开奖励整的城市有:北 京.成 都.重 庆.上 海.深 圳.长 沙.佛 山.广 州.苏 州.杭 州.南 京.宁 波.青 岛.天 津.西 安.武 汉.厦 门,可按CTRL+F,搜城市名快速查找. ...
随机推荐
- 一周一个小demo — vue.js实现备忘录功能
这个vue实现备忘录的功能demo是K在github上找到的,K觉得这是一个用来对vue.js入门的一个非常简单的demo,所以拿在这里共享一下. (尊重他人劳动成果,从小事做起~ demo原git ...
- hdu 1162 Eddy's picture (Kruskal 算法)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...
- 【转】Silverlight无法添加服务引用
引用地址:http://blog.sina.com.cn/s/blog_6e9c36f501017yzv.html 错误如下: 错误 7 自定义工具错误: 无法生成服务引用“ServiceRefere ...
- Qt 之模型/视图(自定义按钮)
https://blog.csdn.net/liang19890820/article/details/50974059 简述 衍伸前面的章节,我们对QTableView实现了数据显示.自定义排序.显 ...
- 从尾到头打印链表(C++和Python 实现)
(说明:本博客中的题目.题目详细说明及参考代码均摘自 “何海涛<剑指Offer:名企面试官精讲典型编程题>2012年”) 题目 输入一个链表的头结点, 从尾到头反过来打印出每个结点的值. ...
- Python log 模块介绍
刚用Python log模块写了一个例子,记录一下. import logging import logging.handlers import os from datetime import dat ...
- SQL点点滴滴_查询类型和索引-转载
当您考虑是否要对列创建索引时, 请估计在查询中使用列的方式, 下表介绍了索引对其有用的查询类型. 表中的示例基于 AdventureWorks2008R2 示例数据库, 在 SQL Server Ma ...
- 【Leetcode】【Medium】Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 6 T ...
- Python学习---重点模块之shelve
简单示例 import shelve f = shelve.open(r'shelve.txt') f['info'] = {'name':'ftl', 'age':23, 'sex': 'male' ...
- 数据结构之排序技术:快速排序、归并排序、堆排序(C++版)
快速排序 #include <iostream> using namespace std; void swap(int num[], int i, int j) { int temp = ...