标签:
public ListNode ReverseList(ListNode head) { ListNode cur = head; ListNode pre = null; ListNode next = null; while (cur != null) { next = cur.next; cur.next = pre; pre = cur; cur = next; } return pre; }
public ListNode ReverseList(ListNode head) { ListNode cur = head; ListNode pre = head; ListNode next = null; //借助栈的数据结构 Stack stack = new Stack(); while(cur!=null){ stack.push(cur.val); cur=cur.next; } while(!stack.isEmpty()){ pre.val=(int) stack.pop(); pre=pre.next; } return head; }
public ListNode ReverseList(ListNode head) { if (null == head || null == head.next) { return head; } ListNode reversedHead = ReverseList(head.next); head.next.next=head; head.next=null; return reversedHead; }
标签:
原文地址:http://www.cnblogs.com/winAlaugh/p/5348782.html