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). 今天,它发 ...
随机推荐
- python基础学习6----字符串操作
一.重复输出字符串 print('hello'*20)#输出20个hello 二.通过索引获取字符串中字符 print('helloworld'[2:])#输出lloworld 三.关键字 in pr ...
- mysql的“The user specified as a definer (”@’%') does not exist”问题 解决
2017-12-27,MYSQL的存储调用时出现了“The user specified as a definer (”test@’%') does not exist”的问题. 网上查过后,都是提示 ...
- 匿名访问windows server 2008 R2 文件服务器的共享
匿名访问windows server 2008 R2 文件服务器的共享 匿名访问windows 2008 R2 文件服务器的共享,七步:第一步 取消简单文件共享:第二步 设置需要共享的文件夹every ...
- 漏洞扫描--openvas
操作实例演示 0.登录openvas 点击“openvas start”启动openvas相关服务,服务启动成功之后!在浏览器输入网址:https://127.0.0.1/login/login.ht ...
- Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine
在开发中用到Microsoft.ACE.OLEDB.12.0,但是,出现了Microsoft.ACE.OLEDB.12.0' provider is not registered on the l ...
- 【洛谷】【前缀和+st表】P2629 好消息,坏消息
[题目描述:] uim在公司里面当秘书,现在有n条消息要告知老板.每条消息有一个好坏度,这会影响老板的心情.告知完一条消息后,老板的心情等于之前老板的心情加上这条消息的好坏度.最开始老板的心情是0,一 ...
- linux下apache中httpd.conf的ServerAdmin 是设置的什么?
<VirtualHost 127.0.0.1:80> ServerAdmin ******@****.com DocumentRoot /home/aaa/sss ServerName s ...
- iframe-metamask
iframe--require('iframe') higher level api for creating and removing iframes in browsers 用于创建或移除浏览器中 ...
- Spring framework3.2整合hibernate4.1报错:No Session found for current thread
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransact ...
- undefined symbol: ap_log_rerror;apache2.4与weblogic点so文件
没法子啊:只能用 httpd-2.2.26 ============================== https://www.google.com.hk/#newwindow=1&q=un ...