/**
* 反轉鏈表
*
* @param head
* @return
*/
public ListNode reverseListNode(ListNode head) {
if (null == head) {
return null;
}
ListNode res = null;
ListNode cur = head;
while (cur != null) {
//保存當前節點的下一個節點
ListNode next = cur.next;
//將當前節點設置爲頭節點
cur.next = res;
res = cur;
//將下一個節點賦值給當前節點
cur = next;
}
return res;
}
劍指Offer學習-面試題24:反轉鏈表
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.