[Inefficient Java solution] DFS - Beat 5%
\nclass Solution {\n    private static class Result {\n        String value = "";\n    }\n    \n    public String shortestSuperstring(String[] A) {\n        if 
```\nclass Solution {\n    private static class Result {\n        String value = "";\n    }\n    \n    public String shortestSuperstring(String[] A) {\n        if (A.length == 1) return A[0];\n        \n        int[][] subAt = new int[A.length][A.length];\n        for (int i = 0; i < A.length; ++i)\n            for (int j = 0; j < A.length; ++j)\n                if (i != j)\n                    subAt[i][j] = substringAt(A[i], A[j]);\n        \n        Result r = new Result();\n        dfs(A, subAt, new StringBuilder(), -1, 0, new boolean[A.length], r);\n        return r.value;\n    }\n    \n\t// inspired by woshilxd912\n    private void dfs(String[] A, int[][] subAt, StringBuilder path, int last, int depth, boolean[] visited, Result r) {\n        if (depth == A.length) { \n            if (r.value.isEmpty() || r.value.length() > path.length()) r.value = path.toString();\n            return; \n        }\n        if (!r.value.isEmpty() && path.length() >= r.value.length()) return;\n        if (depth == 0) {\n            for (int i = 0; i < A.length; ++i) {\n                visited[i] = true;\n                path.append(A[i]);\n                dfs(A, subAt, path, i, 1, visited, r);\n                path.delete(0, path.length());\n                visited[i] = false;\n            }\n            return;\n        }\n        for (int i = 0; i < A.length; ++i) {\n            if (visited[i]) continue;\n            visited[i] = true;\n            int pathLen = path.length();\n            path.append(A[i].substring(subAt[last][i]));\n            if (r.value.isEmpty() || path.length() < r.value.length())\n                dfs(A, subAt, path, i, depth + 1, visited, r);\n            path.delete(pathLen, path.length());\n            visited[i] = false;\n        }\n    }\n    \n    private int substringAt(String a, String b) {\n        if (a.isEmpty()) return 0;\n        \n        for (int i = Math.min(a.length(), b.length()); i > 0; --i)\n            if (a.endsWith(b.substring(0, i)))\n                return i;\n        \n        return 0;\n    }\n    \n}\n```
[]