File tree Expand file tree Collapse file tree 2 files changed +69
-0
lines changed Expand file tree Collapse file tree 2 files changed +69
-0
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,30 @@ class Solution {
101101}
102102```
103103
104+ ### ** JavaScript**
105+
106+ ``` js
107+ /**
108+ * Definition for singly-linked list.
109+ * function ListNode(val) {
110+ * this.val = val;
111+ * this.next = null;
112+ * }
113+ */
114+ /**
115+ * @param {ListNode} head
116+ * @return {number[]}
117+ */
118+ var reversePrint = function (head ) {
119+ let res = [];
120+ while (head != null ) {
121+ res .unshift (head .val );
122+ head = head .next ;
123+ }
124+ return res;
125+ };
126+ ```
127+
104128### ** Go**
105129
106130``` go
@@ -179,6 +203,31 @@ public:
179203};
180204```
181205
206+ ### ** TypeScript**
207+
208+ ``` ts
209+ /**
210+ * Definition for singly-linked list.
211+ * class ListNode {
212+ * val: number
213+ * next: ListNode | null
214+ * constructor(val?: number, next?: ListNode | null) {
215+ * this.val = (val===undefined ? 0 : val)
216+ * this.next = (next===undefined ? null : next)
217+ * }
218+ * }
219+ */
220+
221+ function reversePrint(head : ListNode | null ): number [] {
222+ let res: number [] = [];
223+ while (head != null ) {
224+ res .unshift (head .val );
225+ head = head .next ;
226+ }
227+ return res ;
228+ };
229+ ```
230+
182231### ** ...**
183232
184233```
Original file line number Diff line number Diff line change 1+ /**
2+ * Definition for singly-linked list.
3+ * class ListNode {
4+ * val: number
5+ * next: ListNode | null
6+ * constructor(val?: number, next?: ListNode | null) {
7+ * this.val = (val===undefined ? 0 : val)
8+ * this.next = (next===undefined ? null : next)
9+ * }
10+ * }
11+ */
12+
13+ function reversePrint ( head : ListNode | null ) : number [ ] {
14+ let res : number [ ] = [ ] ;
15+ while ( head != null ) {
16+ res . unshift ( head . val ) ;
17+ head = head . next ;
18+ }
19+ return res ;
20+ } ;
You can’t perform that action at this time.
0 commit comments