Find the Shortest Superstring Bugs? | Python
Is there a bug in the leetcode submitting system for this problem? How is this getting accepted?\n\n\nBy the way here is a serious code if you are looking for i
Is there a bug in the leetcode submitting system for this problem? How is ***this*** getting accepted?\n![image](https://assets.leetcode.com/users/images/d4aa48e6-eaa4-4438-9ac2-ff6d0b28dcf6_1621787863.1228492.png)\n\nBy the way here is a serious code if you are looking for it\n```\nclass Solution:\n    def shortestSuperstring(self, words: List[str]) -> str:\n        @lru_cache(None)\n        def connect(w1, w2):\n            return [(w2[i:], len(w2) - i) for i in range(len(w1) + 1) if w1[-i:] == w2[:i] or not i][-1]\n        \n        N = len(words)\n        dp = [[(float("inf"), -1)] * N for _ in range(1<<N)]\n        for i in range(N): dp[1<<i][i] = (len(words[i]), -1)\n            \n        for mask in range(1<<N):\n            n_z_bits = [j for j in range(N) if mask & 1<<j]\n            for j, k in permutations(n_z_bits, 2):\n                dp[mask][j] = min(dp[mask][j], (dp[mask ^ 1<<j][k][0] + connect(words[k], words[j])[1], k))\n                \n        mask = (1<<N) - 1\n        prev = min(dp[mask])\n        last = dp[mask].index(prev)\n        prev = prev[1]\n        ans = ""\n        \n        while prev != -1:\n            ans = connect(words[prev], words[last])[0] + ans\n            mask -= (1<<last)\n            prev, last = dp[mask][prev][1], prev\n            \n        return words[last] + ans\n```
[]