LintCode——Chalkboard XOR Game(黑板游戏)
黑板游戏:
We are given non-negative integers nums[i] which are written on a chalkboard. Alice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first. If erasing a number causes the bitwise XOR of all the elements of the chalkboard to become 0, then that player loses. (Also, we'll say the bitwise XOR of one element is that element itself, and the bitwise XOR of no elements is 0.)
Also, if any player starts their turn with the bitwise XOR of all the elements of the chalkboard equal to 0, then that player wins.
Return True if and only if Alice wins the game, assuming both players play optimally.
样例:
Input: nums = [1, 1, 2]
Output: false
Python:
class Solution:
"""
@param nums: a list of integers
@return: return a boolean
"""
def xorGame(self, nums):
# write your code here
result = 0
for i in nums:
result = result ^ i
if result == 0 or len(nums) % 2 == 0:
return True
else:
return False
LintCode——Chalkboard XOR Game(黑板游戏)的更多相关文章
- [LeetCode] Chalkboard XOR Game 黑板亦或游戏
We are given non-negative integers nums[i] which are written on a chalkboard. Alice and Bob take tu ...
- [Swift]LeetCode810. 黑板异或游戏 | Chalkboard XOR Game
We are given non-negative integers nums[i] which are written on a chalkboard. Alice and Bob take tu ...
- Weekly Contest 78-------->810. Chalkboard XOR Game
We are given non-negative integers nums[i] which are written on a chalkboard. Alice and Bob take tu ...
- 二分+DP+Trie HDOJ 5715 XOR 游戏
题目链接 XOR 游戏 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- HDU 5715 XOR 游戏 二分+字典树
XOR 游戏 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5715 Description 众所周知,度度熊喜欢XOR运算(XOR百科). 今天,它 ...
- ARC122D XOR Game(博弈论?字典树,贪心)
题面 ARC122D XOR Game 黑板上有 2 N 2N 2N 个数,第 i i i 个数为 A i A_i Ai. O I D \rm OID OID(OneInDark) 和 H I D ...
- Swift LeetCode 目录 | Catalog
请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift 说明:题目中含有$符号则为付费题目. 如 ...
- 【LeetCode】数学(共106题)
[2]Add Two Numbers (2018年12月23日,review) 链表的高精度加法. 题解:链表专题:https://www.cnblogs.com/zhangwanying/p/979 ...
- 百度之星复赛 1004 / hdu5715 二分dp+trie
XOR 游戏 Problem Description 众所周知,度度熊喜欢XOR运算[(XOR百科)](http://baike.baidu.com/view/674171.htm). 今天,它发 ...
随机推荐
- Yii2 使用 RESTful 写API接口 实例
Yii2 使用 RESTful? 其实 Yii2 框架本身就对 RESTful 是友好支持的,具体可以看官方文档(http://www.yiichina.com/doc/guide/2.0/rest- ...
- 35_张孝祥Java高新技术_为注解增加各种属性
注解的作用之所以那么强大,就是因为它有属性 注解很像接口,属性很像方法. 什么是注解的属性 一个注解相当于一个胸牌,如果你胸前贴了胸牌,就是传智播客的学生,否则,就不是.如果还想区分出事传智播客 ...
- time模块案例演示
案例01: 2008年8月8日20:08:08 往后88,888,888秒是哪天?星期几? 日期->时间戳(浮点数)->可以做数学运算 演示: import time # 构造日期的元组, ...
- IIS 部署SSL证书
1.导入证书 打开IIS服务管理器,点击计算机名称,双击‘服务器证书 双击打开服务器证书后,点击右则的导入 选择证书文件,点击确定 2.站点开启SSL 选择证书文件,点击确定 点击网站下的站点名称,点 ...
- [ML学习笔记] 决策树与随机森林(Decision Tree&Random Forest)
[ML学习笔记] 决策树与随机森林(Decision Tree&Random Forest) 决策树 决策树算法以树状结构表示数据分类的结果.每个决策点实现一个具有离散输出的测试函数,记为分支 ...
- php 微信公众号接入支付宝支付
真是无力吐槽这个需求了,好端端的非要在微信公众号接入支付宝,都知道微信公众号是拒绝支付宝的,屏蔽了支付宝,所以在微信公众号接入支付宝的话就必须手动复制链接跳出微信内置浏览器,强制性打开web浏览器完成 ...
- docker 1.13.1 启动容器过程中mount报错
docker 1.13.1 启动container 问题 [root@openfalcon_transfer1 harbor]# docker run -it --name test busybox ...
- 2.2.2 RelativeLayout(相对布局)
本节引言 在上一节中我们对LinearLayout进行了详细的解析,LinearLayout也是我们 用的比较多的一个布局,我们更多的时候更钟情于他的weight(权重)属性,等比例划分,对屏幕适配还 ...
- 连接远程数据库ORACLE11g,错误百出!
客户机中PLSQL DEV访问虚拟机中的ORACLE11g,错误百出! 创建时间: 2017/10/14 18:44 作者: CNSIMO 标签: ORACLE 忙了一下午,只有两个字形容:麻烦! ...
- Linux防火墙工具Firestarter
Firestarter是一个非常好用的防火墙图形化配置工具,作者和开发者是芬兰人. 首先肯定的说Firestarter防火墙是一款非常优秀的基于GUI图形用户界面下的,完全免费的自由软件,它为中小型L ...