File tree 2 files changed +34
-0
lines changed
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 42
42
3 . [ Bag of Tokens] ( https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/562/week-4-october-22nd-october-28th/3506/ ) ➡️ [ CPP Solution] ( Week4/bagOfTokensScore.cpp )
43
43
4 . [ Stone Game IV] ( https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/562/week-4-october-22nd-october-28th/3507/ ) ➡️ [ CPP Solution] ( Week4/winnerSquareGame.cpp )
44
44
5 . [ Champagne Tower] ( https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/562/week-4-october-22nd-october-28th/3508/ ) ➡️ [ CPP Solution] ( Week4/champagneTower.cpp )
45
+ 6 . [ Linked List Cycle II] ( https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/562/week-4-october-22nd-october-28th/3509/ ) ➡️ [ CPP Solution] ( Week4/detectCycle.cpp )
45
46
46
47
## Week 5 🚧
47
48
Original file line number Diff line number Diff line change
1
+ /* *
2
+ * Definition for singly-linked list.
3
+ * struct ListNode {
4
+ * int val;
5
+ * ListNode *next;
6
+ * ListNode(int x) : val(x), next(NULL) {}
7
+ * };
8
+ */
9
+ class Solution {
10
+ public:
11
+ ListNode *detectCycle (ListNode *head) {
12
+ if (head == NULL ) return NULL ;
13
+
14
+ ListNode* slow = head;
15
+ ListNode* fast = head;
16
+
17
+ while (fast != NULL && fast->next != NULL ) {
18
+ slow = slow->next ;
19
+ fast = fast->next ->next ;
20
+
21
+ if (slow == fast) {
22
+ slow = head;
23
+ while (slow != fast) {
24
+ slow = slow->next ;
25
+ fast = fast->next ;
26
+ }
27
+ return slow;
28
+ }
29
+ }
30
+
31
+ return NULL ;
32
+ }
33
+ };
You can’t perform that action at this time.
0 commit comments