diff --git a/高频面试系列/一行代码解决的智力题.md b/高频面试系列/一行代码解决的智力题.md index 1d17782..67ec0d7 100644 --- a/高频面试系列/一行代码解决的智力题.md +++ b/高频面试系列/一行代码解决的智力题.md @@ -149,4 +149,53 @@ int bulbSwitch(int n) {

-======其他语言代码====== \ No newline at end of file +======其他语言代码====== + +由[JodyZ0203](https://github.com/JodyZ0203)提供 292. Nim 游戏 Python3 解法代码: +```Python3 +class Solution: + def canWinNim(self, n: int) -> bool: + # 如果除于是0,说明是4的倍数,所以必输 + # 否则不是除于不等于0,说明不是4的倍数,说明必胜 + return n % 4 != 0 +``` + +由[JodyZ0203](https://github.com/JodyZ0203)提供 877. 石子游戏 Python3 解法代码: +```Python3 +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& piles) { + // 双方都很聪明的前提下, 先手必胜无疑 + return true; + } +}; +``` + + +由[JodyZ0203](https://github.com/JodyZ0203)提供 319. 灯泡开关 Python3 解法代码: +```Python3 +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)); + } +}; +```