Python Backtracking with Explaination
python\nfrom itertools import permutations\n\nclass Solution:\n    def __init__(self):\n        self.eps = 0.001\n    \n    def judgePoint24(self, cards: List[i
```python\nfrom itertools import permutations\n\nclass Solution:\n    def __init__(self):\n        self.eps = 0.001\n    \n    def judgePoint24(self, cards: List[int]) -> bool:\n        \n        # solve the nums to get 24\n        def solve(nums: int) -> bool:\n            # no operation\n            if len(nums) == 1:\n                return abs(nums[0] - 24) <= self.eps\n            \n            # take any two and do an operation\n            # test if the result can be formed to 24 with the rest\n            return any(\n                solve([x] + rest)\n                for a, b, *rest in permutations(nums)\n                for x in {a + b, a - b, a * b, 0 if b == 0 else a / b}\n            )\n                \n        return solve(cards)\n```
[]