Java Trie solution easy and clear
\nclass Solution {\n    class Trie {\n        class Node {\n            Node[] next = new Node[26];\n            boolean isEnd;\n        }\n        Node root;\n
```\nclass Solution {\n    class Trie {\n        class Node {\n            Node[] next = new Node[26];\n            boolean isEnd;\n        }\n        Node root;\n        public Trie() {\n            root = new Node();\n            root.isEnd = true;\n        }\n        public void insert(String s) {\n            Node node = root;\n            for(char c : s.toCharArray()) {\n                if(node.next[c - 'a'] == null) node.next[c - 'a'] = new Node();\n                node = node.next[c - 'a'];\n            }\n            node.isEnd = true;\n        }\n        public boolean canForm(String s) {\n            Node node = root;\n            for(char c : s.toCharArray()) {\n                if(node.next[c - 'a'] == null || !node.isEnd) return false;\n                node = node.next[c - 'a'];\n            }\n            return true;\n        }\n    }\n    public String longestWord(String[] words) {\n        Trie t = new Trie();\n        for(String w : words) t.insert(w);\n        String res = "";\n        for(String w : words) {\n            if(w.length() >= res.length() && t.canForm(w)) {\n                if(w.length() > res.length()) res = w;\n                else res = w.compareTo(res) < 0 ? w : res;\n            }\n        }\n        return res;\n    }\n}\n```
[]