LintCode——Chalkboard XOR Game(黑板游戏)
2024-08-26 10:08:24
黑板游戏:
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
最新文章
- 【原创】PageAdminCMS 前台SQL注入漏洞(2)
- 新版markdown功能发布!支持github flavored markdown!
- Java调优经验谈
- git 初次使用
- Mysql存储引擎
- OC错误
- VBS创建数据库
- 学习selenium需要具备的知识或技术
- UIScrollView 滚动停止的时候一次调用此方法
- Delphi 重启应用程序(创建Bat文件的Process)
- 高质量程序设计指南C/C++语言——有了malloc/free为什么还要new/delete?
- [Python]Unicode转ascii码的一个好方法
- cocos2dx对于强大的RichText控制
- Entity Framework+SQLite+DataBaseFirst
- Android通过Apk插件调起微信支付
- 老李分享:Android性能优化之内存泄漏2
- OBJ-C中dispatch_once的用法
- 集成学习之Boosting —— AdaBoost原理
- Centos7 安装mysql-8.0.13(rpm)
- Java课堂笔记(零):内容索引
热门文章
- python-异常处理try_except
- PHP支付宝支付开发流程
- Linux之因BASH造成的键盘错误和环境问题
- 5.Dubbo2.5.3泛化引用和泛化实现
- 8.3Solr API使用(StatsComponent聚合统计)
- 【FRM123】Wrong Way Risk
- MFC单文档视图拆分窗口和相关链接
- scrapy (三)各部分意义及框架示意图详解
- DQN(Deep Reiforcement Learning) 发展历程(五)
- js 按指定属性给对象数组排序(json数组)