Python Backtracking
Inspired by https://leetcode.com/problems/24-game/discuss/1062871/Python-dfs\nPlease check out and like his post.\nI just changed the ops handling to my preferr
Inspired by https://leetcode.com/problems/24-game/discuss/1062871/Python-dfs\nPlease check out and like his post.\nI just changed the ops handling to my preferred method with fewer special cases.\nI was previously doing backtracking by deleting and inserting indexes back into the cards array. I like this more because it doesn\'t have any `O(n)` array operations.\n```\nops = [lambda a,b: a+b, lambda a,b: a*b, lambda a,b: a-b, lambda a,b: b-a, lambda a,b: a/b, lambda a,b: b/a]\n\nclass Solution:\n    def judgePoint24(self, cards: List[int]) -> bool:\n        def backtrack(n: int) -> bool:\n            if n == 1:\n                return abs(cards[0] - 24) < 0.01\n            for i in range(n):\n                a = cards[i]\n                for j in range(i+1, n):\n                    b = cards[j]\n                    cards[j] = cards[n-1]\n                    for op in ops:\n                        try:\n                            cards[i] = op(a,b)\n                            if backtrack(n-1):\n                                return True\n                        except ZeroDivisionError:\n                            pass\n                    cards[j] = b\n                cards[i] = a\n            return False\n        return backtrack(4)\n```
['Backtracking', 'Python']