MCPcopy
hub / github.com/qiyuangong/leetcode / dfs

Method dfs

java/720_Longest_Word_in_Dictionary.java:57–77  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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}

Callers 1

longestWordMethod · 0.95

Calls 3

pushMethod · 0.95
emptyMethod · 0.95
popMethod · 0.95

Tested by

no test coverage detected