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

Method near

src/class129/Code05_RoadTrip.java:94–117  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

92 }
93
94 public static void near() {
95 for (int i = 1; i <= n; i++) {
96 rank[i][0] = i;
97 rank[i][1] = arr[i];
98 }
99 Arrays.sort(rank, 1, n + 1, (a, b) -> a[1] - b[1]);
100 rank[0][0] = 0;
101 rank[n + 1][0] = 0;
102 for (int i = 1; i <= n; i++) {
103 last[rank[i][0]] = rank[i - 1][0];
104 next[rank[i][0]] = rank[i + 1][0];
105 }
106 for (int i = 1; i <= n; i++) {
107 to1[i] = 0;
108 dist1[i] = 0;
109 to2[i] = 0;
110 dist2[i] = 0;
111 update(i, last[i]);
112 update(i, last[last[i]]);
113 update(i, next[i]);
114 update(i, next[next[i]]);
115 delete(i);
116 }
117 }
118
119 public static void update(int i, int j) {
120 if (j == 0) {

Callers 1

mainMethod · 0.95

Calls 3

updateMethod · 0.95
deleteMethod · 0.95
sortMethod · 0.45

Tested by

no test coverage detected