Python3 solution with eval()
Here I just simulate all permutations of numbers and operators and use the builtin eval() function to get the result. There are 6 different cases for parenthese
Here I just simulate all permutations of numbers and operators and use the builtin eval() function to get the result. There are 6 different cases for parentheses and I iterate through all of them.\n\n```\n    def judgePoint24(self, nums: List[int]) -> bool:\n\n        @lru_cache(None)\n        def solve(a, b, c, d):\n            for op1, op2, op3 in itertools.product(\'/*-+\', repeat=3):\n                for case in [\n                        \'{}{}{}{}{}{}{}\',  # without parentheses\n                        \'({}{}{}){}{}{}{}\',  # parentheses around a and b\n                        \'{}{}{}{}({}{}{})\',  # parentheses around c and d\n                        \'({}{}{}{}{}){}{}\',  # parentheses around a, b and c\n                        \'{}{}({}{}{}{}{})\',  # parentheses around b, c and d\n                        \'({}{}{}){}({}{}{})\']:  # parentheses around a and b and around c and d\n                    try:\n                        if math.isclose(24, eval(case.format(a, op1, b, op2, c, op3, d))):\n                            return True\n                    except ZeroDivisionError:\n                        pass\n\n        return any(solve(a, b, c, d) for a, b, c, d in itertools.permutations(nums))\n```
[]