当前位置:网站首页>[daily training -- Tencent selected 50] 292 Nim games
[daily training -- Tencent selected 50] 292 Nim games
2022-07-07 05:49:00 【Puppet__】
subject
You and your friends , Play with two people Nim game :
There is a pile of stones on the table .
You take turns in your rounds , You are the first to .
Every round , It's your turn to take it off 1 - 3 A stone .
The man who takes the last stone is the winner .
Let's assume that every step is the optimal solution . Please write a function , To determine if you can give a given number of stones n Win the game without . If you can win , return true; otherwise , return false .
Example 1:
Input :n = 4
Output :false
explain : Here are the possible results :
- remove 1 A stone . Your friend moved away 3 A stone , Including the last piece . Your friend won .
- remove 2 A stone . Move your friend 2 A stone , Including the last piece . Your friend won .
3. You move 3 Stone . Your friend removed the last stone . Your friend won .
Of all the results , Your friend is the winner .
Example 2:
Input :n = 1
Output :true
Example 3:
Input :n = 2
Output :true
Tips :
1 <= n <= 231 - 1
Code
class Solution {
// simplify nim game
public boolean canWinNim(int n) {
// As long as you always have four left for each other, you can guarantee your victory
return n % 4 != 0;
}
}
边栏推荐
- pytorch_ 01 automatic derivation mechanism
- Taobao Commodity details page API interface, Taobao Commodity List API interface, Taobao Commodity sales API interface, Taobao app details API interface, Taobao details API interface
- R language [logic control] [mathematical operation]
- 《2022中国低/无代码市场研究及选型评估报告》发布
- Input of native applet switches between text and password types
- 4. Object mapping Mapster
- Flinksql 读写pgsql
- Hcip eighth operation
- Taobao commodity details page API interface, Taobao commodity list API interface, Taobao commodity sales API interface, Taobao app details API interface, Taobao details API interface
- 力扣102题:二叉树的层序遍历
猜你喜欢
5. Data access - entityframework integration
Paper reading [semantic tag enlarged xlnv model for video captioning]
[paper reading] semi supervised left atrium segmentation with mutual consistency training
Common skills and understanding of SQL optimization
Harmonyos practice - Introduction to development, analysis of atomized services
OpenSergo 即将发布 v1alpha1,丰富全链路异构架构的服务治理能力
Message queuing: how to ensure that messages are not lost
Paper reading [MM21 pre training for video understanding challenge:video captioning with pre training techniqu]
JD commodity details page API interface, JD commodity sales API interface, JD commodity list API interface, JD app details API interface, JD details API interface, JD SKU information interface
Five core elements of architecture design
随机推荐
OpenSergo 即将发布 v1alpha1,丰富全链路异构架构的服务治理能力
Get the way to optimize the one-stop worktable of customer service
An example of multi module collaboration based on NCF
消息队列:如何确保消息不会丢失
Mysql-centos7 install MySQL through yum
404 not found service cannot be reached in SAP WebService test
分布式全局ID生成方案
Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game
分布式事务解决方案之2PC
Type de texte de commutation d'entrée et de mot de passe de l'applet natif
Message queue: how to deal with message backlog?
[paper reading] semi supervised left atrium segmentation with mutual consistency training
bat 批示处理详解
Go language context explanation
Distributed global ID generation scheme
Pinduoduo product details interface, pinduoduo product basic information, pinduoduo product attribute interface
Introduction to distributed transactions
爬虫练习题(三)
nodejs获取客户端ip
English grammar_ Noun possessive