# Smart-Hypercube/leetcode

Switch branches/tags
Nothing to show
Fetching contributors…
Cannot retrieve contributors at this time
63 lines (61 sloc) 1.98 KB
 s = {6667, 1557, 1558, 6677, 6678, 2599, 1577, 6699, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1119, 7777, 1122, 1123, 1124, 1125, 7778, 7779, 7788, 1133, 7789, 2677, 7799, 6777, 6778, 6779, 1667, 6788, 1159, 1677, 1678, 1167, 5777, 5778, 1177, 1178, 1179, 1189, 5799, 4779, 2222, 1199, 2226, 8888, 8889, 8899, 1222, 1223, 7888, 2777, 2779, 7899, 2279, 2799, 1777, 1778, 2299, 5899, 9999, 1299, 2334, 3358, 8999, 3388, 7999, 1355, 6999, 1899, 4459, 5999, 4466, 4467, 4999, 3467, 4499, 3488, 5557, 5558, 2999, 5569, 5579, 1999, 1499, 3555, 3577, 2555, 2556} class Solution: def judgePoint24(self, nums): """ :type nums: List[int] :rtype: bool """ nums.sort() return nums[0] * 1000 + nums[1] * 100 + nums[2] * 10 + nums[3] not in s '''My original program: ls = [ '((%d %s %d) %s %d) %s %d == 24', '%d %s ((%d %s %d) %s %d) == 24', '(%d %s (%d %s %d)) %s %d == 24', '%d %s (%d %s (%d %s %d)) == 24', '(%d %s %d) %s (%d %s %d) == 24', ] ds = ( (0, 1, 2, 3), (0, 1, 3, 2), (0, 2, 1, 3), (0, 2, 3, 1), (0, 3, 1, 2), (0, 3, 2, 1), (1, 0, 2, 3), (1, 0, 3, 2), (1, 2, 0, 3), (1, 2, 3, 0), (1, 3, 0, 2), (1, 3, 2, 0), (2, 1, 0, 3), (2, 1, 3, 0), (2, 0, 1, 3), (2, 0, 3, 1), (2, 3, 1, 0), (2, 3, 0, 1), (3, 1, 2, 0), (3, 1, 0, 2), (3, 2, 1, 0), (3, 2, 0, 1), (3, 0, 1, 2), (3, 0, 2, 1), ) class Solution: def judgePoint24(self, nums): """ :type nums: List[int] :rtype: bool """ for l in ls: for o1 in '+-*/': for o2 in '+-*/': for o3 in '+-*/': for d1, d2, d3, d4 in ds: try: if eval(l % (nums[d1], o1, nums[d2], o2, nums[d3], o3, nums[d4])): return True except: pass return False '''