2022-10-01-141-环形链表

1 · zhuba-Ahhh · Oct. 1, 2022, 1:42 p.m.
141. 环形链表哈希JS12345678910111213141516171819202122232425/** * Definition for singly-linked list. * function ListNode(val) { * this.val = val; * this.next = null; * } *//** * @param {ListNode} head * @return {boolean} */var hasCycle = function(head) { if (head == null || head.next == null) { return false; } let map = new Map(); while (head != null) { if (map.has(head)) { return true; } map.set(head, true); head = head.next; } r...