varreversePrint=function(head){let result =[];fn(head, result);return result;}functionfn(head, result){if(head){fn(head.next, result);
result.push(head.val);}}
2.翻转链表
<script>varreversePrint=function(head){let pre =null;let cur = head;let result =[]while(head){
head = head.next;
cur.next = pre;
pre = cur;
cur = head;}while(pre){
result.push(pre.val);
pre = pre.next;}}return result;</script>
3.开辟数组,顺序遍历,最后翻转数组
varreversePrint=function(head){let result =[];while(head){
result.push(result.val);
head = head.next;}return result.reverse();}