File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
32623263class 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
You can’t perform that action at this time.
0 commit comments