()
| 55 | } |
| 56 | |
| 57 | public String dfs() { |
| 58 | String ans = ""; |
| 59 | Stack<Node> stack = new Stack(); |
| 60 | stack.push(root); |
| 61 | while (!stack.empty()) { |
| 62 | Node node = stack.pop(); |
| 63 | if (node.end > 0 || node == root) { |
| 64 | if (node != root) { |
| 65 | String word = words[node.end - 1]; |
| 66 | if (word.length() > ans.length() || |
| 67 | word.length() == ans.length() && word.compareTo(ans) < 0) { |
| 68 | ans = word; |
| 69 | } |
| 70 | } |
| 71 | for (Node nei: node.children.values()) { |
| 72 | stack.push(nei); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | return ans; |
| 77 | } |
| 78 | } |
no test coverage detected