链表相关的操作
链表是否有环
// 判断是否有环,有返回入口节点,无返回null·
let hasCycle = function(head) {
let set = new Set();
while (head != null) {
if (set.has(head)) {
return head;
} else {
set.add(head)
head = head.next;
}
}
return null;
};let hasCycle = function(head) {
try{
JSON.stringify(head);
return false;
}
catch(err){
return true;
}
};
链表反转(反转链表)
链表倒数第 k 个节点
合并两个有序链表
两两交换链表中的节点
反转从位置 m 到 n 的链表
删除中间节点
最后更新于