从尾到头打印链表
1 //输入一个链表,从尾到头打印链表每个节点的值 2 3 /*function ListNode(x){ 4 this.val = x; 5 this.next = null; 6 }*/ 7 function printListFromTailToHead(head) 8 { 9 if(!head){ 10 return 0; 11 }else{ 12 var arr = []; 13 var cur = head; 14 while(cur){ 15 arr.push(cur.val); 16 cur = cur.next; 17 } 18 return arr.reverse(); 19 } 20 }
练习地址:从尾到头打印链表