题目:
单链表的逆转
有解题思路代码很好写,下面的图是C语言的的,但是一看就可以明白。来源:https://www.jianshu.com/p/4664af99b597
代码:
class Solution { public ListNode reverseList(ListNode head) { if (head == null) return null; else if (head.next == null) return head; else { ListNode a = null; ListNode s = head; while(head != null) { head = head.next; s.next = a; a = s; s = head; } return a; } } }