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 following types:
Integer
(one round's score): Directly represents the number of points you get in this round."+"
(one round's score): Represents that the points you get in this round are the sum of the last twovalid
round's points."D"
(one round's score): Represents that the points you get in this round are the doubled data of the lastvalid
round's points."C"
(an operation, which isn't a round's score): Represents the lastvalid
round's points you get were invalid and should be removed.
Each round's operation is permanent and could have an impact on the round before and the round after.
You need to return the sum of the points you could get in all the rounds.
题目分析及思路
题目规定了四种字符:整数字符即是这一轮的所得分数,‘+’表示该轮分数是前两轮有效分数的和,‘D’表示该轮分数是前一轮有效分数的翻倍,‘C’表示上轮分数无效。最后给出所有轮数结束后的总得分。可以遍历每个字符,对每个字符做条件判断,将有效分数存在一个列表里。最后返回列表的和。
python代码
class Solution:
def calPoints(self, ops: List[str]) -> int:
res = []
for op in ops:
if op == 'C':
res.pop()
elif op == '+':
res.append(res[-1] + res[-2])
elif op == 'D':
res.append(2 * res[-1])
else:
res.append(int(op))
return sum(res)
LeetCode 682 Baseball Game 解题报告的更多相关文章
- 【LeetCode】682. Baseball Game 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 使用栈模拟 日期 题目地址:https://leet ...
- LeetCode 1 Two Sum 解题报告
LeetCode 1 Two Sum 解题报告 偶然间听见leetcode这个平台,这里面题量也不是很多200多题,打算平时有空在研究生期间就刷完,跟跟多的练习算法的人进行交流思想,一定的ACM算法积 ...
- 【LeetCode】Permutations II 解题报告
[题目] Given a collection of numbers that might contain duplicates, return all possible unique permuta ...
- 【LeetCode】Island Perimeter 解题报告
[LeetCode]Island Perimeter 解题报告 [LeetCode] https://leetcode.com/problems/island-perimeter/ Total Acc ...
- 【LeetCode】01 Matrix 解题报告
[LeetCode]01 Matrix 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/01-matrix/#/descripti ...
- 【LeetCode】Largest Number 解题报告
[LeetCode]Largest Number 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/largest-number/# ...
- 【LeetCode】Gas Station 解题报告
[LeetCode]Gas Station 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/gas-station/#/descr ...
- 【LeetCode】120. Triangle 解题报告(Python)
[LeetCode]120. Triangle 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址htt ...
- LeetCode: Unique Paths II 解题报告
Unique Paths II Total Accepted: 31019 Total Submissions: 110866My Submissions Question Solution Fol ...
随机推荐
- Android Studio原生库创建示例
[时间:2017-07] [状态:Open] [关键词:Android,Android Studio,gradle,native,c,c++,cmake,原生开发] 0 引言 最近在工作中遇到了升级A ...
- windows_硬盘上设置虚拟内存
1)在桌面上的“计算机”或“我的电脑”上右键->属性->高级->性能->设置->高级->虚拟内存->更改. 2)在虚拟内存更改页面,先选择在哪个磁盘上设置虚拟 ...
- django 返回 code 405
return HttpResponse('Invalid Method',status=405)
- select理解
https://www.cnblogs.com/skyfsm/p/7079458.html
- Install elasticsearch-head: – for Elasticsearch 5.x
Running as a plugin of Elasticsearch Install elasticsearch-head:– for Elasticsearch 5.x:site plugins ...
- Mysql系列二:Mysql 开发标准规范
原文链接:http://www.cnblogs.com/liulei-LL/p/7729983.html 一.表设计 1. 库名.表名.字段名使用小写字母,“_”分割. 2. 库名.表名.字段名不超过 ...
- windows server 2008 R2 计划任务备份系统
实验环境拓扑图: 实验效果: Windows Server Backup 可以设置备份计划,但只能按日进行备份,不能设置按周或月进行备份.所以,需要使用到 windows Server 2008 R2 ...
- SSM框架搭建教程(从零开始,图文结合)
1.准备 IntelliJ IDEA Tomcat JDK Maven mysql spring.springmvc.mybatis 了解 现在假设如上条件你都具备,那么通过我这篇博客 你一定可以整合 ...
- HttpWatch的Result中出现Aborted的原因分析
我们在使用HttpWatch进行Web调试的过程中有时候会看到非HTTP Status Code(状态码)的值,例如:(Aborted). (Aborted)是HttpWatch中定义的三种非HTTP ...
- vs2017企业版本安装和序列号
离线包大概下载为19G,可以选择的选择项很多,很不错,安装如下: 安装完成 启动效果 SharePoint插件自带了 离线包(19G) Visual Studio 2017(VS2017) 企业版En ...