Python, Time: O(1)[100.0%], Space: O(1)[100.0%], precalculation, cheat solution
\nBy just list all cases, it can run very fase!!!\nThis kinds of precalculate cheat are common skill to let program even more faster.\nHowever, it still need a 
\nBy just list all cases, it can run very fase!!!\nThis kinds of precalculate cheat are common skill to let program even more faster.\nHowever, it still need a right solution to generate all cases.\n(Markdown didn\'t work in result which will let this arcitle a littlle bit messy :p)\n\n====================================================================================================\n\n## 1. Precalculate - True cases\n### There have totally 404 cases\n```python\n# Dev: Chumicat\n# Date: 2019/11/30\n# Submission: https://leetcode.com/submissions/detail/282501398/\n# (Time, Space) Complexity : O(1), O(1)\n\ncases = {(1, 2, 5, 5), (2, 5, 6, 8), (3, 3, 7, 7), (3, 5, 7, 9), (1, 4, 6, 7), (5, 5, 9, 9), (3, 3, 3, 9), (2, 2, 6, 6), (2, 4, 6, 8), (1, 5, 5, 6), (3, 4, 4, 7), (1, 3, 8, 9), (1, 2, 4, 8), (4, 8, 8, 8), (2, 2, 2, 8), (3, 6, 6, 8), (1, 2, 5, 9), (5, 6, 7, 9), (1, 7, 7, 9), (2, 3, 4, 4), (2, 2, 5, 9), (1, 3, 4, 7), (2, 3, 5, 5), (3, 3, 3, 4), (2, 5, 5, 7), (1, 6, 6, 9), (4, 6, 7, 9), (1, 3, 5, 8), (5, 5, 5, 6), (5, 5, 8, 8), (2, 5, 8, 8), (3, 5, 6, 7), (2, 2, 2, 3), (3, 5, 7, 8), (1, 4, 6, 6), (2, 3, 4, 8), (2, 4, 5, 6), (2, 3, 5, 9), (2, 4, 6, 7), (1, 5, 5, 5), (1, 6, 9, 9), (1, 3, 8, 8), (1, 2, 4, 7), (3, 4, 7, 8), (3, 3, 6, 9), (3, 6, 6, 7), (6, 6, 7, 9), (4, 4, 5, 5), (2, 2, 4, 7), (4, 5, 9, 9), (1, 2, 7, 8), (1, 4, 5, 5), (4, 6, 6, 7), (2, 2, 5, 8), (1, 3, 4, 6), (1, 1, 4, 7), (1, 2, 8, 9), (3, 7, 7, 9), (1, 6, 6, 8), (4, 6, 7, 8), (1, 3, 5, 7), (1, 1, 5, 8), (1, 5, 5, 9), (3, 5, 6, 6), (5, 6, 6, 8), (4, 5, 6, 8), (2, 3, 4, 7), (6, 7, 9, 9), (1, 4, 5, 9), (2, 4, 5, 5), (3, 4, 6, 6), (2, 8, 8, 8), (5, 8, 8, 8), (4, 4, 4, 4), (2, 3, 7, 8), (3, 3, 5, 7), (3, 4, 7, 7), (2, 3, 8, 9), (1, 3, 3, 5), (3, 3, 6, 8), (2, 2, 4, 6), (1, 2, 7, 7), (2, 2, 2, 4), (2, 6, 7, 9), (2, 3, 3, 6), (4, 6, 6, 6), (1, 3, 4, 5), (1, 1, 4, 6), (3, 7, 7, 8), (2, 2, 8, 9), (1, 3, 7, 7), (1, 5, 7, 9), (4, 4, 4, 8), (4, 8, 9, 9), (4, 5, 5, 6), (1, 2, 3, 5), (1, 3, 3, 9), (5, 6, 6, 7), (4, 5, 6, 7), (1, 1, 8, 8), (1, 4, 4, 7), (2, 4, 4, 9), (1, 4, 5, 8), (2, 3, 7, 7), (3, 3, 5, 6), (1, 2, 6, 6), (2, 5, 7, 9), (1, 4, 8, 9), (3, 3, 8, 8), (1, 2, 3, 9), (1, 3, 3, 4), (4, 4, 8, 9), (3, 3, 9, 9), (2, 2, 4, 5), (2, 4, 4, 4), (2, 2, 7, 7), (2, 6, 7, 8), (2, 3, 3, 5), (2, 4, 7, 9), (1, 2, 2, 4), (3, 7, 7, 7), (1, 1, 3, 9), (2, 2, 8, 8), (2, 6, 8, 9), (3, 4, 6, 9), (1, 5, 7, 8), (4, 4, 4, 7), (3, 5, 5, 9), (4, 5, 5, 5), (1, 2, 3, 4), (1, 3, 3, 8), (5, 6, 6, 6), (2, 2, 3, 5), (4, 4, 7, 8), (1, 7, 8, 9), (1, 4, 4, 6), (3, 6, 8, 9), (2, 4, 4, 8), (1, 3, 6, 9), (2, 3, 3, 9), (1, 2, 2, 8), (1, 4, 7, 7), (1, 1, 3, 4), (1, 6, 7, 9), (4, 6, 8, 9), (3, 4, 5, 8), (1, 4, 8, 8), (2, 6, 6, 7), (3, 5, 8, 9), (1, 3, 3, 3), (2, 2, 3, 9), (3, 6, 7, 8), (1, 1, 2, 7), (2, 4, 7, 8), (1, 5, 6, 6), (3, 9, 9, 9), (3, 3, 4, 5), (1, 1, 3, 8), (1, 2, 6, 9), (5, 5, 6, 7), (2, 5, 6, 7), (3, 5, 5, 8), (6, 6, 6, 6), (1, 1, 6, 9), (2, 2, 3, 4), (3, 4, 9, 9), (5, 7, 7, 9), (4, 4, 7, 7), (3, 3, 3, 8), (2, 4, 4, 7), (1, 3, 6, 8), (1, 2, 2, 7), (3, 4, 4, 6), (3, 3, 4, 9), (4, 6, 8, 8), (3, 4, 5, 7), (1, 3, 9, 9), (4, 5, 7, 9), (2, 2, 2, 7), (2, 3, 6, 9), (1, 2, 5, 8), (2, 6, 6, 6), (3, 5, 8, 8), (5, 6, 7, 8), (2, 2, 3, 8), (5, 6, 8, 9), (3, 3, 3, 3), (2, 8, 9, 9), (4, 5, 8, 9), (3, 6, 7, 7), (1, 1, 2, 6), (2, 2, 6, 9), (3, 3, 4, 4), (3, 8, 8, 9), (5, 5, 5, 5), (6, 8, 8, 9), (1, 1, 3, 7), (5, 5, 6, 6), (2, 5, 6, 6), (1, 1, 6, 8), (2, 2, 3, 3), (2, 7, 7, 8), (3, 7, 8, 9), (3, 3, 3, 7), (2, 3, 5, 8), (2, 4, 6, 6), (3, 4, 4, 5), (1, 5, 8, 9), (5, 5, 5, 9), (1, 2, 4, 6), (3, 7, 9, 9), (3, 4, 5, 6), (4, 5, 7, 8), (3, 6, 6, 6), (1, 2, 5, 7), (4, 4, 6, 9), (5, 6, 7, 7), (3, 3, 7, 9), (1, 4, 6, 9), (6, 6, 8, 9), (2, 2, 5, 7), (1, 2, 8, 8), (2, 4, 5, 9), (4, 6, 7, 7), (2, 2, 6, 8), (1, 3, 5, 6), (1, 1, 5, 7), (3, 4, 4, 9), (2, 3, 9, 9), (4, 4, 5, 8), (2, 3, 4, 6), (3, 7, 8, 8), (1, 3, 4, 9), (2, 3, 5, 7), (3, 3, 3, 6), (2, 5, 5, 9), (4, 7, 7, 8), (3, 4, 4, 4), (1, 5, 8, 8), (1, 2, 4, 5), (4, 7, 8, 9), (2, 3, 8, 8), (3, 3, 6, 7), (3, 5, 6, 9), (1, 5, 9, 9), (3, 3, 7, 8), (6, 6, 8, 8), (2, 2, 5, 6), (1, 3, 4, 4), (1, 1, 4, 5), (2, 4, 5, 8), (1, 6, 6, 6), (1, 1, 5, 6), (1, 2, 4, 9), (4, 5, 6, 6), (4, 4, 5, 7), (2, 2, 4, 9), (2, 3, 4, 5), (1, 4, 5, 7), (4, 6, 6, 9), (1, 3, 4, 8), (1, 1, 4, 9), (4, 7, 7, 7), (3, 3, 5, 5), (5, 5, 7, 8), (2, 5, 7, 8), (1, 2, 4, 4), (4, 5, 5, 9), (1, 2, 3, 8), (3, 3, 6, 6), (5, 5, 8, 9), (2, 5, 8, 9), (3, 5, 6, 8), (4, 4, 8, 8), (2, 2, 4, 4), (1, 8, 8, 9), (2, 3, 4, 9), (1, 1, 1, 8), (2, 2, 5, 5), (1, 1, 4, 4), (2, 4, 5, 7), (2, 6, 8, 8), (2, 4, 8, 9), (3, 4, 6, 8), (4, 4, 4, 6), (3, 3, 5, 9), (1, 1, 5, 5), (3, 4, 7, 9), (1, 2, 3, 3), (1, 3, 3, 7), (1, 7, 8, 8), (1, 4, 4, 5), (4, 4, 5, 6), (2, 2, 4, 8), (3, 6, 8, 8), (1, 2, 7, 9), (1, 7, 9, 9), (1, 4, 5, 6), (2, 3, 3, 8), (4, 6, 6, 8), (3, 6, 9, 9), (1, 1, 4, 8), (5, 7, 8, 9), (1, 3, 7, 9), (5, 5, 7, 7), (2, 5, 7, 7), (1, 6, 8, 9), (4, 6, 9, 9), (4, 5, 5, 8), (1, 2, 3, 7), (5, 6, 6, 9), (3, 5, 9, 9), (4, 5, 6, 9), (1, 4, 4, 9), (1, 8, 8, 8), (2, 3, 3, 3), (2, 4, 7, 7), (2, 4, 8, 8), (2, 8, 8, 9), (5, 8, 8, 9), (4, 4, 4, 5), (2, 3, 7, 9), (1, 2, 6, 8), (3, 5, 5, 7), (1, 3, 3, 6), (6, 8, 9, 9), (1, 4, 4, 4), (2, 7, 8, 9), (2, 4, 4, 6), (1, 3, 6, 7), (2, 3, 3, 7), (1, 5, 6, 9), (1, 2, 2, 6), (5, 7, 8, 8), (3, 3, 4, 8), (1, 3, 7, 8), (4, 4, 4, 9), (2, 3, 6, 8), (1, 6, 8, 8), (2, 3, 6, 6), (4, 5, 5, 7), (1, 2, 3, 6), (6, 6, 6, 9), (2, 2, 3, 7), (1, 4, 4, 8), (5, 6, 8, 8), (4, 5, 8, 8), (5, 6, 9, 9), (6, 8, 8, 8), (3, 8, 8, 8), (1, 4, 7, 9), (1, 1, 3, 6), (1, 2, 6, 7), (3, 8, 9, 9), (3, 5, 5, 6), (3, 3, 8, 9), (2, 6, 6, 9), (7, 8, 8, 9), (6, 7, 8, 9), (2, 7, 8, 8), (2, 4, 4, 5), (1, 1, 2, 9), (1, 3, 6, 6), (2, 2, 7, 8), (1, 5, 6, 8), (1, 2, 2, 5), (3, 3, 4, 7), (3, 4, 5, 5), (4, 5, 7, 7), (2, 2, 2, 5), (2, 3, 6, 7), (1, 2, 5, 6), (2, 5, 6, 9), (4, 4, 6, 8), (6, 6, 6, 8), (2, 2, 3, 6), (1, 4, 6, 8), (4, 4, 7, 9), (2, 2, 6, 7), (1, 2, 2, 9), (2, 4, 6, 9), (3, 4, 4, 8), (4, 7, 9, 9), (1, 4, 7, 8), (1, 1, 3, 5), (4, 8, 8, 9), (3, 4, 5, 9), (2, 2, 2, 9), (3, 6, 6, 9), (2, 6, 6, 8), (1, 1, 6, 6), (2, 6, 9, 9), (2, 3, 5, 6), (3, 3, 3, 5), (2, 5, 5, 8), (3, 6, 7, 9), (1, 1, 2, 8), (1, 5, 6, 7), (1, 3, 5, 9), (2, 4, 9, 9), (3, 3, 4, 6), (4, 7, 8, 8), (3, 4, 8, 9), (5, 5, 6, 8)}\nclass Solution:\n    def judgePoint24(self, nums: List[int]) -> bool:\n        return tuple(sorted(nums)) in cases\n```\n### Generate True cases\nTo generate the precalculate case, we will need a correct solution first.\nThen use combinations_with_replacement in itertools to generate all possible input\n```python\nfrom itertools import combinations_with_replacement\ncases = set()\nfor case in combinations_with_replacement(range(10), 4):\n    if judgePoint24(case):\n        cases.append(case)\n```\n\n====================================================================================================\n\n## 2. Precalculate - False cases\nTo get more improvement, we can decrease what we place in set.\nBy just list negative case!\nThere are totally 91 cases\n``` python\n# Dev: Chumicat\n# Date: 2019/11/30\n# Submission: https://leetcode.com/submissions/detail/282590781/\n# (Time, Space) Complexity : O(1), O(1)\nbad_cases = {(4, 4, 6, 7), (2, 2, 9, 9), (1, 1, 7, 9), (1, 1, 1, 5), (1, 1, 9, 9), (2, 2, 2, 6), (1, 1, 2, 3), (5, 5, 7, 9), (3, 5, 5, 5), (1, 7, 7, 7), (1, 8, 9, 9), (2, 5, 9, 9), (3, 4, 6, 7), (2, 5, 5, 5), (1, 1, 2, 5), (1, 6, 6, 7), (1, 5, 5, 8), (5, 9, 9, 9), (6, 7, 7, 8), (1, 1, 6, 7), (1, 1, 5, 9), (2, 2, 7, 9), (6, 6, 6, 7), (1, 6, 7, 7), (7, 7, 7, 8), (1, 1, 7, 8), (5, 5, 5, 8), (7, 7, 8, 9), (1, 1, 1, 7), (6, 6, 7, 7), (3, 3, 5, 8), (1, 1, 1, 9), (4, 4, 9, 9), (1, 3, 5, 5), (1, 4, 9, 9), (2, 6, 7, 7), (1, 5, 5, 7), (2, 3, 3, 4), (1, 2, 2, 3), (5, 7, 7, 7), (1, 1, 1, 2), (2, 7, 7, 7), (6, 6, 9, 9), (1, 5, 7, 7), (5, 8, 9, 9), (8, 8, 8, 8), (3, 4, 8, 8), (2, 9, 9, 9), (6, 7, 7, 7), (4, 4, 6, 6), (5, 7, 9, 9), (8, 8, 9, 9), (1, 1, 1, 4), (2, 7, 7, 9), (8, 9, 9, 9), (7, 7, 7, 7), (1, 1, 8, 9), (1, 1, 2, 2), (2, 7, 9, 9), (5, 5, 6, 9), (4, 4, 5, 9), (7, 7, 8, 8), (7, 9, 9, 9), (4, 9, 9, 9), (1, 1, 1, 6), (1, 1, 3, 3), (1, 6, 7, 8), (7, 7, 7, 9), (4, 7, 7, 9), (1, 1, 2, 4), (1, 7, 7, 8), (7, 7, 9, 9), (9, 9, 9, 9), (6, 6, 7, 8), (2, 5, 5, 6), (1, 2, 2, 2), (7, 8, 8, 8), (1, 9, 9, 9), (1, 1, 1, 1), (6, 7, 8, 8), (2, 2, 2, 2), (3, 5, 7, 7), (7, 8, 9, 9), (6, 7, 7, 9), (1, 1, 7, 7), (5, 7, 7, 8), (1, 1, 1, 3), (5, 5, 5, 7), (1, 2, 9, 9), (6, 9, 9, 9), (8, 8, 8, 9)}\nclass Solution:\n    def judgePoint24(self, nums: List[int]) -> bool:\n        return tuple(sorted(nums)) not in bad_cases\n```\n### Generate False cases\nYou can generate cases by this\n```python\nfrom itertools import combinations_with_replacement\nbad_cases = set()\nfor case in combinations_with_replacement(range(1,10), 4):\n    if not judgePoint24(case):\n        bad_cases.add(case)\n```\n\n====================================================================================================\n\n## 3. Precalculate - False cases (let\'s go further)\nOk, since input number are restricted in 1 to 9, we can append it as a 4 digits number.\nRemember to sort the nums!!\n``` python\n# Dev: Chumicat\n# Date: 2019/11/30\n# Submission: https://leetcode.com/submissions/detail/282596555/\n# (Time, Space) Complexity : O(1), O(1)\nbad_cases = {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, 7999, 1355, 6999, 1899, 4459, 5999, 4466, 4467, 4999, 3467, 4499, 3488, 5557, 5558, 2999, 5569, 5579, 1999, 1499, 3555, 3577, 2555, 2556}\nclass Solution:\n    def judgePoint24(self, nums: List[int]) -> bool:\n        return int("".join(map(str, sorted(nums)))) not in bad_cases\n```\n### Generate False cases (let\'s go further)\nSince we use combinations_with_replacement, we do not need to worry about the sorting problem.\n```python\nfrom itertools import combinations_with_replacement\nbad_cases = set()\nfor case in combinations_with_replacement(range(1,10), 4):\n    if not judgePoint24(case):\n        bad_cases.add(int("".join(map(str, case))))\n```\n\n====================================================================================================\n\n## 4. Precalculate - False cases (The crazy one, ver Garbled English)\nAnd finally, let\'s make a trade-off between clean code and efficiency.\nBy change number to characer can even minimize code layout space.\nUse string to store each character rather than use set will decrease effeciency but keep code cleaner.\n\n``` python\n# Dev: Chumicat\n# Date: 2019/11/30\n# Submission: https://leetcode.com/submissions/detail/282599601/\n# (Time, Space) Complexity : O(1), O(1)\nbad_cases = "\u0D1E\u04A5\u09FC\u0459\u06F2\u04C7\u1E77\u08E7\u048F\u1E6C\u0464\u0DE3\u05DB\u1A15\u0458\u22B8\u06F1\u1173\u0683\u0A75\u1193\u22B9\u1E63\u045F\u08B2\u0AD9\u1A79\u1E62\u046D\u2327\u1A7B\u045D\u270F\u176F\u049A\u068D\u1691\u0AEF\u15B6\u15B5\u15C1\u1F3F\u076B\u1B57\u1A16\u116B\u0615\u04C6\u0BB7\u1E61\u1EDB\u1387\u08AE\u15CB\u0499\u0DF9\u1A84\u045A\u0465\u0D8B\u1A0B\u0DA0\u09FB\u1692\u22C3\u04AF\u1ED0\u054B\u0462\u045C\u0513\u07CF\u16A7\u0457\u0487\u0463\u091E\u0A27\u0629\u045B\u1A7A\u08FB\u0616\u12AB\u049B\u170B\u1172\u0ADB\u1E6D\u068E\u1A2B"\nclass Solution:\n    def judgePoint24(self, nums: List[int]) -> bool:\n        return chr(int(\'\'.join(map(str, sorted(nums)))) + 0) not in bad_cases\n```\n### Generate False cases (The crazy one, ver Garbled English)\n```python\nfrom itertools import combinations_with_replacement\ncases = set()\nfor case in combinations_with_replacement(range(1,10), 4):\n    if not judgePoint24(case):\n        cases.add(chr(int("".join(map(str, case)))))\ns = "".join(cases)\n```\n\n====================================================================================================\n\n## 5. Precalculate - False cases (The crazy one, ver Garbled  Chinese)\nIf you afraid the symbol that can\'t show on screen, try Chinese version\nBy shift symbol to unicode Chinese range where start from 19968, you store it in Chinese\n``` python\n# Dev: Chumicat\n# Date: 2019/11/30\n# Submission: https://leetcode.com/submissions/detail/282598893/\n# (Time, Space) Complexity : O(1), O(1)\nbad_cases = "\u687B\u5B8B\u525A\u63C1\u5299\u70B8\u5258\u548D\u5415\u6816\u63B5\u6187\u5313\u529A\u6C77\u58D9\u58DB\u5262\u70B9\u58EF\u56E7\u53DB\u5F73\u525D\u6C62\u63B6\u5BF9\u526D\u5263\u5264\u6C6C\u5F93\u56FB\u55CF\u6C6D\u6492\u5827\u52C6\u57FB\u5265\u525F\u656F\u6491\u6884\u60AB\u6CDB\u6C63\u750F\u57FC\u5429\u525B\u5259\u6D3F\u54F1\u5287\u6815\u63CB\u548E\u7127\u5BA0\u6879\u52AF\u6C61\u525C\u534B\u556B\u680B\u5875\u52A5\u5483\u5BE3\u650B\u6957\u52C7\u56AE\u5B1E\u6CD0\u70C3\u571E\u528F\u5416\u56B2\u682B\u5F72\u687A\u5257\u64A7\u54F2\u59B7\u5F6B\u529B"\nclass Solution:\n    def judgePoint24(self, nums: List[int]) -> bool:\n        return chr(int(\'\'.join(map(str, sorted(nums)))) + 19968) not in bad_cases\n```\n### Generate False cases (The crazy one, ver Garbled Chinese)\n```python\nfrom itertools import combinations_with_replacement\ncases = set()\nfor case in combinations_with_replacement(range(1,10), 4):\n    if not judgePoint24(case):\n        cases.add(chr(int("".join(map(str, case)))+19968))\ns = "".join(cases)\n```
['Python', 'Python3']