Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6a21bef

Browse files
author
Swastikyadav
committed
Implement midPoint solution for a linkedList
1 parent 74768ef commit 6a21bef

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

‎DsAlgo-Questions/19-midPoint.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ function midPoint(arr) {
3131
return arr[slow];
3232
}
3333

34+
// Implementation for linked list.
35+
/*
36+
function midPointOfLinkedlist(list) {
37+
let slow = 0;
38+
let fast = 0;
39+
40+
while (fast.next && fast.next.next) {
41+
slow = slow.next;
42+
fast = fast.next.next;
43+
}
44+
45+
return slow;
46+
}
47+
*/
48+
3449
console.log(midPoint(oddArr)); // 9
3550
console.log(midPoint(evenArr)); // 5
3651

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /