Reverse Print 2021-06-24 05:20
public int[] reversePrint(ListNode head) {
ListNode p = head;
int count = 0;
while (p != null) {
p = p.next;
count++;
}
int[] res = new int[count];
int index = res.length - 1;
while (head != null) {
res[index] = head.val;
head = head.next;
index--;
}
return res;
}
Runtime | Memory |
---|---|
0 ms | 39 MB |
EOF