[Java] Clean code with Trie
\npublic List<String> findAllConcatenatedWordsInADict(String[] words) {\n        List<String> result = new ArrayList<>();     \n        Trie root = new Trie();\
``` \npublic List<String> findAllConcatenatedWordsInADict(String[] words) {\n        List<String> result = new ArrayList<>();     \n        Trie root = new Trie();\n        // Insert each word \n        for (String word : words) {\n            if (word.length() == 0) continue;\n            Trie node = root;         \n            for (char c : word.toCharArray()) {\n                if (node.next[c - \'a\'] == null) \n                    node.next[c - \'a\'] = new Trie();\n                node = node.next[c - \'a\'];\n            }\n            node.word = word;\n        }    \n        for (String word : words)\n            if (search(word, 0, root, root))\n                result.add(word);\n        \n        return result;\n    }\n    \n    private boolean search(String word, int index, Trie node, Trie root) {\n        // tricky : the last word of the concatenated word is definitely storing the last word\n        if (index == word.length())\n            return node.word != null && !node.word.equals(word); \n        \n        Trie current = node.next[word.charAt(index) - \'a\'];\n        \n        if (current == null) return false;\n        \n        // only time when you found word and the search for the rest of the words are true which is searched from the root\n        if (current.word != null && \n            search(word, index + 1, root, root)) return true;\n        \n        // Keep moving with the next index\n        return search(word, index + 1, current, root);\n    }\n    \n    class Trie {\n        Trie[] next = new Trie[26];\n        String word;\n    }\n```
[]