[LeetCode&Python] Problem 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.
Example:
Input:4
Output: false
Explanation: 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:
def canWinNim(self, n):
"""
:type n: int
:rtype: bool
"""
return n%4!=0
[LeetCode&Python] Problem 292. Nim Game的更多相关文章
- [LeetCode&Python] Problem 108. Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Fo ...
- [LeetCode&Python] Problem 387. First Unique Character in a String
Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...
- [LeetCode&Python] Problem 427. Construct Quad Tree
We want to use quad trees to store an N x N boolean grid. Each cell in the grid can only be true or ...
- [LeetCode&Python] Problem 371. Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...
- [LeetCode&Python] Problem 520. Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not. We define the u ...
- [LeetCode&Python] Problem 226. Invert Binary Tree
Invert a binary tree. Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: 4 / \ 7 2 / \ / \ 9 6 3 1 Tr ...
- [LeetCode&Python] Problem 905: Sort Array By Parity
Given an array A of non-negative integers, return an array consisting of all the even elements of A, ...
- [LeetCode&Python] Problem 1: Two Sum
Problem Description: Given an array of integers, return indices of the two numbers such that they ad ...
- [LeetCode&Python] Problem 682. Baseball Game
You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 ...
随机推荐
- Django之用户认证功能
前言 做web应用对登录做用户身份认证,然后设置session是必不可少的,因为我们就需要把有权限访问本站视图的用户,单独建一张表记录到数据库里: Django作为一个大而全的框架,已经为我们做好了这 ...
- ActiveMQ 的连接和会话
要了解 connection 和 session 的概念,可以先从 ConnectionState 和 SessionState 入手: // 省略部分代码 public class Connecti ...
- K-Means ++ 和 kmeans 区别
Kmeans算法的缺陷 聚类中心的个数K 需要事先给定,但在实际中这个 K 值的选定是非常难以估计的,很多时候,事先并不知道给定的数据集应该分成多少个类别才最合适Kmeans需要人为地确定初始聚类中心 ...
- span 超出部分换行
span{ word-break: normal; width: auto; display: block; white-space: pre-wrap; word-wrap: break-word; ...
- 常用的flex知识 ,比起float position 好用不少
flex布局具有便捷.灵活的特点,熟练的运用flex布局能解决大部分布局问题,这里对一些常用布局场景做一些总结. web页面布局(topbar + main + footbar) 示例代码 要 ...
- Echarts dataZoom缩放功能参数详解:
dataZoom=[ //区域缩放 { id: 'dataZoomX', show:true, //是否显示 组件.如果设置为 false,不会显示,但是数据过滤的功能还存在. backgroundC ...
- Google Protocol Buffers 反序列化 转
http://www.cnblogs.com/royenhome/archive/2010/10/30/1865256.html 本文作为结束篇,会稍微介绍下怎么反序列化GoogleBuffer数 ...
- Laravel框架如何去除URL中的/public
laravel/server.php改名为index.php 并且将public目录下的.htaccess拷贝到Larvael根目下 再访问 如有配置不成功的请加群
- 分析图第二讲导出图片和后期PS5.12
导出渲染的白模加上EXTRATEX.再导出一张“消隐”样式的模型图片.就是线稿图. 再导出一张着色显示图,并去掉边线.,用于后期PS选择范围用. 把这几张图全都导入ps. 渲染图的阴影面是灰色的,示例 ...
- vue安装与配置
直接引入 <script src="https://unpkg.com/vue"></script> 用npm安装 $ npm install vue ...