未验证 提交 af6787e6 编写于 作者: B BruceCat 提交者: GitHub

【292/877/319 一行代码解决的智力题】【Python3】

【292/877/319 一行代码解决的智力题】【Python3】
......@@ -149,4 +149,58 @@ int bulbSwitch(int n) {
<img src="../pictures/qrcode.jpg" width=200 >
</p>
======其他语言代码======
\ No newline at end of file
======其他语言代码======
[JodyZ0203](https://github.com/JodyZ0203)提供 292. Nim 游戏 Python3 解法代码:
```Python
class Solution:
def canWinNim(self, n: int) -> bool:
# 如果除于是0,说明是4的倍数,所以必输
# 否则不是除于不等于0,说明不是4的倍数,说明必胜
return n % 4 != 0
```
[JodyZ0203](https://github.com/JodyZ0203)提供 877. 石子游戏 Python3 解法代码:
```Python
class Solution:
def stoneGame(self, piles: List[int]) -> bool:
# 双方都很聪明的前提下, 先手必胜无疑
# 先手可以提前观察偶数堆还是基数的石头总数更多
return True
```
[JodyZ0203](https://github.com/JodyZ0203)提供 877. 石子游戏 C++ 解法代码:
```cpp
class Solution {
public:
bool stoneGame(vector<int>& piles) {
// 双方都很聪明的前提下, 先手必胜无疑
return true;
}
};
```
[JodyZ0203](https://github.com/JodyZ0203)提供 319. 灯泡开关 Python3 解法代码:
```Python
class Solution:
def bulbSwitch(self, n: int) -> int:
# 平方根电灯个数之后向下取整即可
return floor(sqrt (n))
```
[JodyZ0203](https://github.com/JodyZ0203)提供 319. 灯泡开关 C++ 解法代码:
```cpp
class Solution {
public:
int bulbSwitch(int n) {
// 平方根电灯个数之后向下取整即可
return floor(sqrt (n));
}
};
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册