剑指offer 6.20

2019-06-20  本文已影响0人  HannahLi_9f1c

/**

*/
import java.util.ArrayList;
public class Solution {
public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
ListNode pPre = null;
ListNode pCur = listNode;
ListNode pNext = null;
while(pCur != null){
pNext = pCur.next;
pCur.next = pPre;
pPre = pCur;
pCur = pNext;
}
ArrayList<Integer> result = new ArrayList<Integer>();
while(pPre!=null){
result.add(pPre.val);
pPre = pPre.next;
}
return result;

}

}

上一篇 下一篇

猜你喜欢

热点阅读