您的位置:首页 > 其它

Reverse Linked List

2016-05-24 10:42 155 查看
题目描述:

Reverse a singly linked list.

很简单,必须一次ac。

public ListNode reverseList(ListNode head) {
if(head==null){
return null;
}
ListNode last=head;
while(last.next!=null){
last=last.next;
}
while(head!=last){
ListNode next=head.next;
head.next=last.next;
last.next=head;
head=next;
}
return head;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: