黑板游戏:

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

最新文章

  1. 【原创】PageAdminCMS 前台SQL注入漏洞(2)
  2. 新版markdown功能发布!支持github flavored markdown!
  3. Java调优经验谈
  4. git 初次使用
  5. Mysql存储引擎
  6. OC错误
  7. VBS创建数据库
  8. 学习selenium需要具备的知识或技术
  9. UIScrollView 滚动停止的时候一次调用此方法
  10. Delphi 重启应用程序(创建Bat文件的Process)
  11. 高质量程序设计指南C/C++语言——有了malloc/free为什么还要new/delete?
  12. [Python]Unicode转ascii码的一个好方法
  13. cocos2dx对于强大的RichText控制
  14. Entity Framework+SQLite+DataBaseFirst
  15. Android通过Apk插件调起微信支付
  16. 老李分享:Android性能优化之内存泄漏2
  17. OBJ-C中dispatch_once的用法
  18. 集成学习之Boosting —— AdaBoost原理
  19. Centos7 安装mysql-8.0.13(rpm)
  20. Java课堂笔记(零):内容索引

热门文章

  1. python-异常处理try_except
  2. PHP支付宝支付开发流程
  3. Linux之因BASH造成的键盘错误和环境问题
  4. 5.Dubbo2.5.3泛化引用和泛化实现
  5. 8.3Solr API使用(StatsComponent聚合统计)
  6. 【FRM123】Wrong Way Risk
  7. MFC单文档视图拆分窗口和相关链接
  8. scrapy (三)各部分意义及框架示意图详解
  9. DQN(Deep Reiforcement Learning) 发展历程(五)
  10. js 按指定属性给对象数组排序(json数组)