当前位置:网站首页>[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;
}
}
边栏推荐
- 4. Object mapping Mapster
- 谈fpga和asic的区别
- In memory, I moved from CSDN to blog park!
- Flinksql 读写pgsql
- zabbix_get测试数据库失败
- TCC of distributed transaction solutions
- 《HarmonyOS实战—入门到开发,浅析原子化服务》
- SQL query: subtract the previous row from the next row and make corresponding calculations
- 微信小程序蓝牙连接硬件设备并进行通讯,小程序蓝牙因距离异常断开自动重连,js实现crc校验位
- win配置pm2开机自启node项目
猜你喜欢

Modes of optical fiber - single mode and multimode

Hcip seventh operation

Hcip eighth operation

How digitalization affects workflow automation

Message queuing: how to ensure that messages are not lost

分布式事务解决方案之TCC

数据中心为什么需要一套基础设施可视化管理系统

基于NCF的多模块协同实例

pytorch_ 01 automatic derivation mechanism

5. 数据访问 - EntityFramework集成
随机推荐
SAP ABAP BDC (batch data communication) -018
pytorch_ 01 automatic derivation mechanism
AI人脸编辑让Lena微笑
分布式事务解决方案之TCC
分布式全局ID生成方案
Common skills and understanding of SQL optimization
[PM products] what is cognitive load? How to adjust cognitive load reasonably?
[binary tree] binary tree path finding
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
Harmonyos practice - Introduction to development, analysis of atomized services
Leetcode: maximum number of "balloons"
Dj-zbs2 leakage relay
EMMC打印cqhci: timeout for tag 10提示分析与解决
What are the common message queues?
Bat instruction processing details
Paper reading [open book video captioning with retrieve copy generate network]
Paper reading [MM21 pre training for video understanding challenge:video captioning with pre training techniqu]
《2022中国低/无代码市场研究及选型评估报告》发布
产业金融3.0:“疏通血管”的金融科技
SAP ABAP BDC(批量数据通信)-018