LintCode Reverse LinkedList (ArrayList 和 LinkedList 的区别)

2022-11-23,,,,

1. ArrayList 和 LinkedList 的区别

http://pengcqu.iteye.com/blog/502676

2. How to reverse LinkedList

http://www.java2blog.com/2014/07/how-to-reverse-linked-list-in-java.html

/**
* Definition for ListNode.
* public class ListNode {
* int val;
* ListNode next;
*
* ListNode(int val) {
* this.val = val;
* this.next = null;
* }
* }
*/
public class Solution {
/**
* @param head: The head of linked list.
* @return: The new head of reversed linked list.
*/
public ListNode reverse(ListNode head) {
ListNode preNode = null;
ListNode nextNode;
ListNode curNode = head;
while(curNode != null){
nextNode = curNode.next;
curNode.next = preNode;
preNode = curNode;
curNode = nextNode;
}
return preNode;// write your code here
}
}

LintCode Reverse LinkedList (ArrayList 和 LinkedList 的区别)的相关教程结束。

《LintCode Reverse LinkedList (ArrayList 和 LinkedList 的区别).doc》

下载本文的Word格式文档,以方便收藏与打印。