Download pool/shard004/Python/0035849_679TwentyFourGame.py from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard004/Python/0035849_679TwentyFourGame.py
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard004/Python/0035849_679TwentyFourGame.py
-
curl -L -o 0035849_679TwentyFourGame.py https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard004/Python/0035849_679TwentyFourGame.py
1.07 kB
| class Solution: | |
| def judgePoint24(self, nums): | |
| """ | |
| :type nums: List[int] | |
| :rtype: bool | |
| """ | |
| def dfs(nums): | |
| if len(nums) == 1: | |
| if abs(nums[0] - 24) < 0.001: | |
| return True | |
| for i in range(len(nums)): | |
| for j in range(i): | |
| a, b = nums[i], nums[j] | |
| nums.pop(i) | |
| nums.pop(j) | |
| nxt = [a+b, a-b, b-a, a*b] | |
| if abs(a) > 0.001: | |
| nxt.append(b / a) | |
| if abs(b) > 0.001: | |
| nxt.append(a / b) | |
| for n in nxt: | |
| nums.append(n) | |
| if dfs(nums): | |
| return True | |
| nums.pop() | |
| nums.insert(j, b) | |
| nums.insert(i, a) | |
| return False | |
| return dfs(nums) |