LintCode Reverse LinkedList (ArrayList 和 LinkedList 的区别)

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
}
}
上一篇:iOS网络-03-NSURLSession与NSURLSessionTask


下一篇:对pymysql的简单封装