MCPcopy Create free account
hub / github.com/algorithmzuo/algorithm-journey / lca

Method lca

src/class161/Code02_LCA1.java:157–166  ·  view source on GitHub ↗
(int a, int b)

Source from the content-addressed store, hash-verified

155 }
156
157 public static int lca(int a, int b) {
158 while (top[a] != top[b]) {
159 if (dep[top[a]] <= dep[top[b]]) {
160 b = fa[top[b]];
161 } else {
162 a = fa[top[a]];
163 }
164 }
165 return dep[a] <= dep[b] ? a : b;
166 }
167
168 public static void main(String[] args) throws IOException {
169 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected