-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy path4.java
More file actions
32 lines (29 loc) · 669 Bytes
/
4.java
File metadata and controls
32 lines (29 loc) · 669 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public int[] reversePrint(ListNode head) {
int length=changdu(head);
int []nums=new int[length];
bianli(head,nums,length);
return nums;
}
int changdu(ListNode head){
int count=0;
while(head!=null){
count++;
head=head.next;
}
return count;
}
void bianli(ListNode head,int []nums,int i){
if(head==null) return ;
bianli(head.next,nums,i-1);
nums[i-1]=head.val;
}
}