标签:display http ever 链接 div lap val ast fas
package 链表; /** * https://leetcode-cn.com/problems/delete-node-in-a-linked-list/ * @author MJ Lee * */ public class _237_删除链表中的节点 { public void deleteNode(ListNode node) { node.val = node.next.val; node.next = node.next.next; } }
public ListNode reverseList(ListNode head) { if (head == null || head.next == null) return head; ListNode newHead = reverseList(head.next); head.next.next = head; head.next = null; return newHead; }
public ListNode reverseList2(ListNode head) { if (head == null || head.next == null) return head; ListNode newHead = null; while (head != null) { //tmp的作用临时变了 保存变量值 防止节点引用断裂 从而被gc误删 ListNode tmp = head.next; head.next = newHead; newHead = head; head = tmp; } return newHead; }
public boolean hasCycle(ListNode head) { if (head == null || head.next == null) return false; ListNode slow = head; ListNode fast = head.next; while (fast != null && fast.next != null) { slow = slow.next; fast = fast.next.next; if (slow == fast) return true; } return false; }
标签:display http ever 链接 div lap val ast fas
原文地址:https://www.cnblogs.com/ggnbnb/p/12166005.html