当前位置:网站首页>[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;
}
}
边栏推荐
- bat 批示处理详解
- 消息队列:如何确保消息不会丢失
- How digitalization affects workflow automation
- SAP ABAP BDC(批量数据通信)-018
- Red Hat安装内核头文件
- zabbix_ Get test database failed
- 拼多多商品详情接口、拼多多商品基本信息、拼多多商品属性接口
- How to get free traffic in pinduoduo new store and what links need to be optimized in order to effectively improve the free traffic in the store
- 京东商品详情页API接口、京东商品销量API接口、京东商品列表API接口、京东APP详情API接口、京东详情API接口,京东SKU信息接口
- PowerPivot——DAX(函数)
猜你喜欢
随机推荐
Web Authentication API兼容版本信息
Leakage relay jelr-250fg
nodejs获取客户端ip
【已解决】记一次EasyExcel的报错【读取xls文件时全表读不报错,指定sheet名读取报错】
Distributed global ID generation scheme
What is message queuing?
[shell] clean up nohup Out file
PowerPivot——DAX(函数)
OpenSergo 即将发布 v1alpha1,丰富全链路异构架构的服务治理能力
How to get free traffic in pinduoduo new store and what links need to be optimized in order to effectively improve the free traffic in the store
Taobao store release API interface (New), Taobao oauth2.0 store commodity API interface, Taobao commodity release API interface, Taobao commodity launch API interface, a complete set of launch store i
SQL query: subtract the previous row from the next row and make corresponding calculations
Input of native applet switches between text and password types
产业金融3.0:“疏通血管”的金融科技
软件测试面试技巧
盘点国内有哪些EDA公司?
make makefile cmake qmake都是什么,有什么区别?
[论文阅读] A Multi-branch Hybrid Transformer Network for Corneal Endothelial Cell Segmentation
STM32按键状态机2——状态简化与增加长按功能
Explication contextuelle du langage Go