题目 定义一个函数,输入一个链表的头结点,反转该链表并输出反转后链表的头结点。 实现 12345678 public class { int val; ListNode next = null; ListNode(int val) { this.val = val; }} 123456789101112131415161718 public ListNode ReverseList(ListNode head) { ListNode current = head; ListNode previous = null; ListNode tail = null; while (current != null){ ListNode next = current.next; if (next == null) tail = current; current.next = previous; previous = current; current = next; } return tail;} 赞微海报分享
近期评论