Backtracking Simple Python Solution - Without Estimation
The logic behind this solution is that every number is stored as (numerator, denominator). \n From the array of length n, 2 numbers are picked\n\t All 4 operati
The logic behind this solution is that every number is stored as `(numerator, denominator)`. \n* From the array of length `n`, 2 numbers are picked\n\t* All 4 operations are done on the picked numbers\n\t* Answer is stored back in the array: array now becomes of length `n-1`\n* Repeated till array length is 1 -> Then the value is checked: `numerator/denominator == 24`\n```\nclass num():\n    def __init__(self, n, d):\n        self.n = n\n        self.d = d\n        \n    def __add__(self, otherNum):\n        n = (self.n * otherNum.d + self.d * otherNum.n)\n        d = self.d * otherNum.d\n        return num(n,d)\n    \n    def __sub__(self, otherNum):\n        n = (self.n * otherNum.d - self.d * otherNum.n)\n        d = self.d * otherNum.d\n        return num(n,d)\n    \n    def __mul__(self, otherNum):\n        n = self.n * otherNum.n\n        d = self.d * otherNum.d\n        return num(n,d)\n    \n    def __truediv__(self, otherNum):\n        n = self.n * otherNum.d\n        d = self.d * otherNum.n\n        return num(n,d)\n    \ndef helper(nums):\n    \n    if len(nums) == 1 and nums[0].d != 0:\n        return True if nums[0].n/nums[0].d == 24 else False\n\n    for i in range(0,len(nums)):\n        for j in range(0, len(nums)):\n            if i!=j:\n                newArr = [nums[k] for k in range(0, len(nums)) if k!=i and k!=j]\n                if helper(newArr + [nums[i] + nums[j]]):\n                    return True\n                if helper(newArr + [nums[i] - nums[j]]):\n                    return True\n                if helper(newArr + [nums[i] * nums[j]]):\n                    return True\n                if helper(newArr + [nums[i] / nums[j]]):\n                    return True\n    return False\n\nclass Solution:\n    def judgePoint24(self, nums):\n        """\n        :type nums: List[int]\n        :rtype: bool\n        """\n        for i in range(len(nums)):\n            nums[i] = num(nums[i], 1)\n            \n        return helper(nums)\n```
[]