Leetcode-cn.com 2021-09-18
🟢 292.nim-game
🏷️ Tags
#brainteaser #math #game_theory
Description
你和你的朋友,两个人一起玩 Nim 游戏:
桌子上有一堆石头。
你们轮流进行自己的回合,你作为先手。
每一回合,轮到的人拿掉 1 - 3 块石头。
拿掉最后一块石头的人就是获胜者。
假设你们每一步都是最优解。请编写一个函数,来判断你是否可以在给定石头数量为
Example
🟢 292.nim-game
🏷️ Tags
#brainteaser #math #game_theory
Description
你和你的朋友,两个人一起玩 Nim 游戏:
桌子上有一堆石头。
你们轮流进行自己的回合,你作为先手。
每一回合,轮到的人拿掉 1 - 3 块石头。
拿掉最后一块石头的人就是获胜者。
假设你们每一步都是最优解。请编写一个函数,来判断你是否可以在给定石头数量为
n 的情况下赢得游戏。如果可以赢,返回 true;否则,返回 false 。Example
输入:n = 4
输出:false
解释:如果堆中有 4 块石头,那么你永远不会赢得比赛;
因为无论你拿走 1 块、2 块 还是 3 块石头,最后一块石头总是会被你的朋友拿走。
百度百科
Nim游戏_百度百科
Nim游戏是博弈论中最经典的模型(之一),它又有着十分简单的规则和无比优美的结论 Nim游戏是组合游戏(Combinatorial Games)的一种,准确来说,属于“Impartial Combinatorial Games”(以下简称ICG)。
Leetcode-cn.com 2021-11-15
🟡 319.bulb-switcher
🏷️ Tags
#brainteaser #math
Description
初始时有
第三轮,你每三个灯泡就切换一个灯泡的开关(即,打开变关闭,关闭变打开)。第
找出并返回
Example
🟡 319.bulb-switcher
🏷️ Tags
#brainteaser #math
Description
初始时有
n 个灯泡处于关闭状态。第一轮,你将会打开所有灯泡。接下来的第二轮,你将会每两个灯泡关闭一个。第三轮,你每三个灯泡就切换一个灯泡的开关(即,打开变关闭,关闭变打开)。第
i 轮,你每 i 个灯泡就切换一个灯泡的开关。直到第 n 轮,你只需要切换最后一个灯泡的开关。找出并返回
n 轮后有多少个亮着的灯泡。Example
输入:n = 3
输出:1
解释:
初始时, 灯泡状态 [关闭, 关闭, 关闭].
第一轮后, 灯泡状态 [开启, 开启, 开启].
第二轮后, 灯泡状态 [开启, 关闭, 开启].
第三轮后, 灯泡状态 [开启, 关闭, 关闭].
你应该返回 1,因为只有一个灯泡还亮着。
leetcode.com 2023-11-04
🟡1503.last-moment-before-all-ants-fall-out-of-a-plank
🏷️ Tags
#brainteaser #array #simulation
🟡1503.last-moment-before-all-ants-fall-out-of-a-plank
🏷️ Tags
#brainteaser #array #simulation
Telegraph
last-moment-before-all-ants-fall-out-of-a-plank
We have a wooden plank of the length n units. Some ants are walking on the plank, each ant moves with a speed of 1 unit per second. Some of the ants move to the left, the other move to the right. When two ants moving in two different directions meet at some…
leetcode.cn 2025-07-30
🟡2419.longest-subarray-with-maximum-bitwise-and
🏷️ Tags
#bit_manipulation #brainteaser #array
🟡2419.longest-subarray-with-maximum-bitwise-and
🏷️ Tags
#bit_manipulation #brainteaser #array
Telegraph
longest-subarray-with-maximum-bitwise-and
给你一个长度为 n 的整数数组 nums 。 考虑 nums 中进行 按位与(bitwise AND)运算得到的值 最大 的 非空 子数组。
leetcode.com 2025-07-30
🟡2419.longest-subarray-with-maximum-bitwise-and
🏷️ Tags
#bit_manipulation #brainteaser #array
🟡2419.longest-subarray-with-maximum-bitwise-and
🏷️ Tags
#bit_manipulation #brainteaser #array
Telegraph
longest-subarray-with-maximum-bitwise-and
You are given an integer array nums of size n. Consider a non-empty subarray from nums that has the maximum possible bitwise AND.
leetcode.cn 2025-09-05
🟡2749.minimum-operations-to-make-the-integer-zero
🏷️ Tags
#bit_manipulation #brainteaser #enumeration
🟡2749.minimum-operations-to-make-the-integer-zero
🏷️ Tags
#bit_manipulation #brainteaser #enumeration
Telegraph
minimum-operations-to-make-the-integer-zero
给你两个整数:num1 和 num2 。 在一步操作中,你需要从范围 [0, 60] 中选出一个整数 i ,并从 num1 减去 2i + num2 。 请你计算,要想使 num1 等于 0 需要执行的最少操作数,并以整数形式返回。 如果无法使 num1 等于 0 ,返回 -1 。 示例 1: 输入:num1 = 3, num2 = -2 输出:3 解释:可以执行下述步骤使 3 等于 0 : - 选择 i = 2 ,并从 3 减去 22 + (-2) ,num1 = 3 - (4 + (-2)) =…
leetcode.com 2025-09-05
🟡2749.minimum-operations-to-make-the-integer-zero
🏷️ Tags
#bit_manipulation #brainteaser #enumeration
🟡2749.minimum-operations-to-make-the-integer-zero
🏷️ Tags
#bit_manipulation #brainteaser #enumeration
Telegraph
minimum-operations-to-make-the-integer-zero
You are given two integers num1 and num2. In one operation, you can choose integer i in the range [0, 60] and subtract 2i + num2 from num1. Return the integer denoting the minimum number of operations needed to make num1 equal to 0. If it is impossible to…
leetcode.cn 2025-12-10
🟡3577.count-the-number-of-computer-unlocking-permutations
🏷️ Tags
#brainteaser #array #math #combinatorics
🟡3577.count-the-number-of-computer-unlocking-permutations
🏷️ Tags
#brainteaser #array #math #combinatorics
Telegraph
count-the-number-of-computer-unlocking-permutations
给你一个长度为 n 的数组 complexity。 在房间里有 n 台 上锁的 计算机,这些计算机的编号为 0 到 n - 1,每台计算机都有一个 唯一 的密码。编号为 i 的计算机的密码复杂度为 complexity[i]。 编号为 0 的计算机密码已经 解锁 ,并作为根节点。其他所有计算机必须通过它或其他已经解锁的计算机来解锁,具体规则如下:
leetcode.com 2025-12-10
🟡3577.count-the-number-of-computer-unlocking-permutations
🏷️ Tags
#brainteaser #array #math #combinatorics
🟡3577.count-the-number-of-computer-unlocking-permutations
🏷️ Tags
#brainteaser #array #math #combinatorics
Telegraph
count-the-number-of-computer-unlocking-permutations
You are given an array complexity of length n. There are n locked computers in a room with labels from 0 to n - 1, each with its own unique password. The password of the computer i has a complexity complexity[i]. The password for the computer labeled 0 is…