File tree 2 files changed +39
-0
lines changed
2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 42
42
119|[ Pascal's Triangle II] ( ./0119-pascals-triangle-ii.js ) |Easy|
43
43
121|[ Best Time to Buy and Sell Stock] ( ./0121-best-time-to-buy-and-sell-stock.js ) |Easy|
44
44
136|[ Single Number] ( ./0136-single-number.js ) |Easy|
45
+ 141|[ Linked List Cycle] ( ./0141-linked-list-cycle.js ) |Easy|
45
46
151|[ Reverse Words in a String] ( ./0151-reverse-words-in-a-string.js ) |Medium|
46
47
152|[ Maximum Product Subarray] ( ./0152-maximum-product-subarray.js ) |Medium|
47
48
217|[ Contains Duplicate] ( ./0217-contains-duplicate.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 141. Linked List Cycle
3
+ * https://leetcode.com/problems/linked-list-cycle/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given head, the head of a linked list, determine if the linked list has a cycle in it.
7
+ *
8
+ * There is a cycle in a linked list if there is some node in the list that can be reached
9
+ * again by continuously following the next pointer. Internally, pos is used to denote the
10
+ * index of the node that tail's next pointer is connected to. Note that pos is not passed
11
+ * as a parameter.
12
+ *
13
+ * Return true if there is a cycle in the linked list. Otherwise, return false.
14
+ */
15
+
16
+ /**
17
+ * Definition for singly-linked list.
18
+ * function ListNode(val) {
19
+ * this.val = val;
20
+ * this.next = null;
21
+ * }
22
+ */
23
+
24
+ /**
25
+ * @param {ListNode } head
26
+ * @return {boolean }
27
+ */
28
+ var hasCycle = function ( head ) {
29
+ while ( head ) {
30
+ if ( head . visited ) {
31
+ return true ;
32
+ }
33
+ head . visited = 1 ;
34
+ head = head . next ;
35
+ }
36
+
37
+ return false ;
38
+ } ;
You can’t perform that action at this time.
0 commit comments