Skip to content

Commit 9a8fe4a

Browse files
authored
Update js codes.docx
1 parent 885e342 commit 9a8fe4a

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

js codes.docx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3257,7 +3257,8 @@ else
32573257
"not anagram of each other");
32583258

32593259
========================================================================================================================================================================
3260-
// How can you make a linkedlist nodes in javascript
3260+
// How can you make a linkedlist nodes in javascript and
3261+
// hpw to check linkedlist is cyclic or not.
32613262

32623263
class LinkedList {
32633264
constructor(data){
@@ -3280,6 +3281,16 @@ D.next = A; //it will be circluar linked list
32803281
//D.next = null; //it will be single linked list
32813282

32823283
//output : 10 -> 20 -> 30 -> 40 -> Null
3284+
3285+
function floyedCycleDetection(){
3286+
let fast = head, slow = head;
3287+
while(fast && fast.next){
3288+
slow = slow.next;
3289+
fast = fast.next.next;
3290+
if(slow == fast) return true;
3291+
}
3292+
return false
3293+
}
32833294
=======================================================================================================================================================================
32843295

32853296

0 commit comments

Comments
 (0)