MCPcopy Create free account
hub / github.com/Ayush7614/Daily-Coding-DS-ALGO-Practice / remove

Method remove

Gfg/Java/Delete_Loop_from_LL.java:141–160  ·  view source on GitHub ↗
(Node head, Node fast, Node slow)

Source from the content-addressed store, hash-verified

139 }
140
141 private static void remove(Node head, Node fast, Node slow) {
142 if (slow == fast) {
143 slow = head;
144 if (slow != fast) {
145 while (slow.next != fast.next) {
146 slow = slow.next;
147 fast = fast.next;
148 }
149 // since fast->next is the looping point
150 fast.next = null; /* remove loop */
151 }
152 // if fast and slow pointer meet at first position.
153 else {
154 while (fast.next != slow) {
155 fast = fast.next;
156 }
157 fast.next = null;
158 }
159 }
160 }
161}
162
163// time complexity : O(N)

Callers 3

removeLoopMethod · 0.95
buildTreeMethod · 0.45
encodeMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected