解答(打败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;
    }
};

笔记

  1. 拿到最后元素有俩种方法
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日)的更多相关文章

  1. 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,若有 ...

  2. 无插件的大模型浏览器Autodesk Viewer开发培训-武汉-2014年8月28日 9:00 – 12:00

    武汉附近的同学们有福了,这是全球第一次关于Autodesk viewer的教室培训. :) 你可能已经在各种场合听过或看过Autodesk最新推出的大模型浏览器,这是无需插件的浏览器模型,支持几十种数 ...

  3. 2015年12月28日 Java基础系列(六)流

    2015年12月28日 Java基础系列(六)流2015年12月28日 Java基础系列(六)流2015年12月28日 Java基础系列(六)流

  4. 2016年11月28日 星期一 --出埃及记 Exodus 20:19

    2016年11月28日 星期一 --出埃及记 Exodus 20:19 and said to Moses, "Speak to us yourself and we will listen ...

  5. 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 ...

  6. 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 ...

  7. 跨界!Omi 发布多端统一框架 Omip 打通小程序与 Web 腾讯开源 2月28日

    https://mp.weixin.qq.com/s/z5qm-2bHk_BCJAwaodrMIg 跨界!Omi 发布多端统一框架 Omip 打通小程序与 Web 腾讯开源 2月28日

  8. 【NEWS】 ADempiere发布ADempiere 3.8.0路线图【2013年7月28日】

    发布源:http://osssme.org/cms/?q=node/17 本以为ADempiere”已死“,但是看到ADempiere的WIKI上大概在从5月28日开始添加WIKI以来,经过多次更新后 ...

  9. 优步UBER司机全国各地奖励政策汇总 (3月28日-4月3日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  10. 全国Uber优步司机奖励政策 (12月28日-1月3日)

    本周已经公开奖励整的城市有:北 京.成 都.重 庆.上 海.深 圳.长 沙.佛 山.广 州.苏 州.杭 州.南 京.宁 波.青 岛.天 津.西 安.武 汉.厦 门,可按CTRL+F,搜城市名快速查找. ...

随机推荐

  1. MySQL数据库备份与还原

    备份数据库 1.使用mysqldump命令备份 备份一个数据库:mysqldump -u 用户名 -p密码 数据库名 [表名1,表名2...]>备份文件路径及名字.sql           如 ...

  2. Spring返回json数据

    第一种形式:使用注解@ResponseBody @RequestMapping(value = "/admin/jq", method = RequestMethod.GET) @ ...

  3. 什么是shell? bash和shell有什么关系?

    什么是Shell?      shell是你(用户)和Linux(或者更准确的说,是你和Linux内核)之间的接口程序.你在提示符下输入的每个命令都由shell先解释然后传给Linux内核.      ...

  4. PHP通过header和meta实现页面编码声明

    一.使用方式: <META http-equiv=”content-type” content=”text/html; charset=xxx”> header(“content-type ...

  5. Maximum Subarray解题报告zz

    http://fisherlei.blogspot.com/2012/12/leetcode-maximum-subarray.html Find the contiguous subarray wi ...

  6. onchange,onfocus ,oninput事件

    compositionstart 在输入一段需要确认的文本如拼音to汉字.语音时会触发 compositionend  在拼音选词完成.语音输入完毕时会触发 addEventListener() 方法 ...

  7. Python学习---重点模块之configparse

    configparse模块常用于生成和修改常见的配置文档 生成配置模块:用字典写 import configparser config = configparser.ConfigParser() co ...

  8. January 14 2017 Week 2nd Saturday

    Don't try so hard, the best things come when you least expect them to. 不要着急,最好的总会在最不经意时出现. The secon ...

  9. ZT 接口和实现分离

    什么叫接口和实现分离,如何实现 [问题点数:20分,结帖人heronism] http://bbs.csdn.net/topics/310212385 http://blog.csdn.net/sta ...

  10. Linux 命令行 发送邮件

    1.mail -s hi xx@yy.com 给xx@yy.com发一封主题为hi的信(没有正文) 编辑完内容后Ctrl-D结束. 2.echo "This is a test mail!& ...