算法空间/Leetcode/从尾到头打印链表:修订间差异
来自康健生活
小 Kangkk移动页面编程语言/从尾到头打印链表至算法空间/从尾到头打印链表,不留重定向 |
|||
(没有差异)
| |||
2024年2月21日 (三) 12:01的版本
题目表述
输入:一个链表
按照链表从尾到头的顺序返回一个数组
const f = (head) => {
const stack = [];
let node = head;
while (node) {
stack.push(node.value);
node = node.next;
}
// return stack.reverse();
const reverse = [];
while (stack.length) {
reverse.push(stack.pop());
}
return reverse;
}
No categories