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

Method update

src/class129/Code05_RoadTrip.java:119–133  ·  view source on GitHub ↗
(int i, int j)

Source from the content-addressed store, hash-verified

117 }
118
119 public static void update(int i, int j) {
120 if (j == 0) {
121 return;
122 }
123 int dist = Math.abs(arr[i] - arr[j]);
124 if (to1[i] == 0 || dist < dist1[i] || (dist == dist1[i] && arr[j] < arr[to1[i]])) {
125 to2[i] = to1[i];
126 dist2[i] = dist1[i];
127 to1[i] = j;
128 dist1[i] = dist;
129 } else if (to2[i] == 0 || dist < dist2[i] || (dist == dist2[i] && arr[j] < arr[to2[i]])) {
130 to2[i] = j;
131 dist2[i] = dist;
132 }
133 }
134
135 public static void delete(int i) {
136 int l = last[i];

Callers 1

nearMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected