zoukankan      html  css  js  c++  java
  • 292. Nim Game

    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.

    此题比较有趣,举例子就可以看的出来了,只要是4的倍数,就会赢的,代码如下:

    1 public class Solution {
    2     public boolean canWinNim(int n) {
    3         if(n%4==0) return false;
    4         else return true;
    5     }
    6 }
  • 相关阅读:
    gin内置验证器使用
    model
    work,工作模式
    orm框架
    simple模式下rabbitmq的代码
    rabbitmq介绍
    订阅模式
    路由模式
    redis五大数据类型
    Go操作redis
  • 原文地址:https://www.cnblogs.com/codeskiller/p/6482027.html
Copyright © 2011-2022 走看看