diff --git a/solutions/059.md b/solutions/059.md new file mode 100644 index 0000000..1290847 --- /dev/null +++ b/solutions/059.md @@ -0,0 +1,13 @@ +### Typescript +141. Linked List Cycle + +```typescript +function hasCycle(head: ListNode | null): boolean { + const check = new Set(); + while(head){ + if(check.has(head)) return true; + check.add(head); + head=head.next + } + return false +};``` \ No newline at end of file diff --git a/solutions/060.md b/solutions/060.md new file mode 100644 index 0000000..e09c6e7 --- /dev/null +++ b/solutions/060.md @@ -0,0 +1,14 @@ +### Typescript +142. Linked List Cycle II + +```Typescript +function detectCycle(head: ListNode | null): ListNode | null { + const check=new Set(); + while(head){ + if(check.has(head)) return head; + check.add(head); + head=head.next + } + return null +}; +``` \ No newline at end of file