博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
leetcode292.[Array] Nim Game
阅读量:4221 次
发布时间:2019-05-26

本文共 732 字,大约阅读时间需要 2 分钟。

You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the winner. You will take the first turn to remove the stones.

Both of you are very clever and have optimal strategies for the game. Write a function to determine whether you can win the game given the number of stones in the heap.

For example, if there are 4 stones in the heap, then you will never win the game: no matter 1, 2, or 3 stones you remove, the last stone will always be removed by your friend.

class Solution(object):    def canWinNim(self,n):        if n%4==0:            return False        else:            return True

转载地址:http://bzqmi.baihongyu.com/

你可能感兴趣的文章
重学设计模式(三)—— 构造器模式
查看>>
Netty框架学习之路(三)—— 初识Netty线程模型
查看>>
重学设计模式(四)—— 原型模式
查看>>
重学设计模式(五)—— 装饰器、适配器、门面和代理
查看>>
Netty框架学习之路(四)—— Channel及相关概念
查看>>
SpringMVC启动过程浅析
查看>>
重学设计模式(六)—— 观察者模式
查看>>
SpringMVC请求处理过程浅析
查看>>
重学设计模式(七)—— 责任链模式
查看>>
Netty框架学习之路(五)—— EventLoop及事件循环机制
查看>>
MyBatis的缓存机制
查看>>
Java中的锁及AQS实现原理
查看>>
MySQL索引及优化
查看>>
MySQL的锁问题
查看>>
Java并发容器及其实现原理
查看>>
JVM调优方法
查看>>
MySQL的高可用
查看>>
Spring的注解驱动开发
查看>>
NoSQL数据库之Redis
查看>>
从IO-BIO-NIO-AIO-到Netty
查看>>