Easy Understand Java code using Dijsktra
\nclass Solution {\n    class State {\n        String word;\n        int mask;\n\n        public State(String word, int mask) {\n            this.word = word;\n
```\nclass Solution {\n    class State {\n        String word;\n        int mask;\n\n        public State(String word, int mask) {\n            this.word = word;\n            this.mask = mask;\n        }\n\n    }\n\n    public String shortestSuperstring(String[] A) {\n        PriorityQueue<State> pq = new PriorityQueue<>((a, b) -> a.word.length() - b.word.length());\n        Set<Integer> set = new HashSet<>();\n\n        int endMask = 0;\n        for (int i = 0; i < A.length; i++) {\n            endMask |= (1 << i);\n        }\n\n        pq.add(new State("", 0));\n\n        while (!pq.isEmpty()) {\n            State cur = pq.poll();\n\n            if (cur.mask == endMask) {\n                return cur.word;\n            }\n\n            if (set.contains(cur.mask))\n                continue;\n\n            set.add(cur.mask);\n\n            for (int i = 0; i < A.length; i++) {\n                if ((cur.mask & (1 << i)) == 0) {\n                    String nextStr1 = merge(cur.word, A[i]);\n                    String nextStr2 = merge(A[i], cur.word);\n                    int nextMask = cur.mask | (1 << i);\n                    pq.add(new State(nextStr1, nextMask));\n                    pq.add(new State(nextStr2, nextMask));\n                }\n            }\n        }\n\n        return null;\n    }\n\n    private String merge(String head, String tail) {\n        int i = 0, j = 0;\n        while (i < head.length()) {\n            if (j < tail.length() && head.charAt(i) == tail.charAt(j)) {\n                i++;\n                j++;\n            } else if (j >= tail.length() && j != 0) {\n                j = 0;\n            } else if (j != 0) {\n                j = 0;\n            } else {\n                i++;\n            }\n        }\n\n        return head + tail.substring(j);\n    }\n}\n```
[]