首页 > 其他 > 详细

LeetCode -- Reverse Linked List

时间:2015-09-19 18:18:50      阅读:220      评论:0      收藏:0      [点我收藏+]
逆转单链表。


思路:
遍历过程中构造一个链栈,返回链栈头结点即可。


实现代码:


/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     public int val;
 *     public ListNode next;
 *     public ListNode(int x) { val = x; }
 * }
 */
public class Solution {
    public ListNode ReverseList(ListNode head) {
        ListNode h = null;
		while(head != null){
			var n = new ListNode(head.val);
			n.next = h;
			h = n;
			head = head.next;
		}
		
		return h;
    }
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

LeetCode -- Reverse Linked List

原文:http://blog.csdn.net/lan_liang/article/details/48576059

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!