MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / createEdges

Method createEdges

java/0269-alien-dictionary.java:8–29  ·  view source on GitHub ↗
(String left, String right)

Source from the content-addressed store, hash-verified

6
7 // Return false if s.len < t.len condition is not met
8 private boolean createEdges(String left, String right) {
9 int minLen = Math.min(left.length(), right.length());
10
11 for (int i = 0; i < minLen; i++) {
12 char first = left.charAt(i), second = right.charAt(i);
13
14 if (first != second) {
15 Set<Character> edges = this.adjList.get(first);
16 edges.add(second);
17 this.adjList.put(first, edges);
18
19 Set<Character> revEdges = this.revList.get(second);
20 revEdges.add(first);
21 this.revList.put(second, revEdges);
22
23 return true;
24 }
25 }
26
27 // No difference found yet, there is a problem
28 return (left.length() <= right.length());
29 }
30
31 private void initialize(String[] words) {
32 // Initialize

Callers 1

alienOrderMethod · 0.95

Calls 3

getMethod · 0.45
addMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected