剑指 Offer 06. 从尾到头打印链表
思路: 定义栈—将链表元素插入进去----完成倒序
public class Solution {
public int[] reversePrint(ListNode head) {
Stack
while (head != null) {
stack.push(head.val);
head = head.next;
}
int size = stack.size();
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = stack.pop();
}
共有 0 条评论