File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -402,6 +402,33 @@ var reversePrint = function (head) {
402
402
};
403
403
```
404
404
405
+ #### Swift
406
+
407
+ ``` swift
408
+ /* public class ListNode {
409
+ * public var val: Int
410
+ * public var next: ListNode?
411
+ * public init(_ val: Int) {
412
+ * self.val = val
413
+ * self.next = nil
414
+ * }
415
+ * }
416
+ */
417
+
418
+ class Solution {
419
+ func reversePrint (_ head : ListNode? ) -> [Int ] {
420
+ var stack = [Int ]()
421
+ var current = head
422
+ while let node = current {
423
+ stack.append (node.val )
424
+ current = node.next
425
+ }
426
+
427
+ return stack.reversed ()
428
+ }
429
+ }
430
+ ```
431
+
405
432
<!-- tabs: end -->
406
433
407
434
<!-- solution: end -->
Original file line number Diff line number Diff line change
1
+ /* public class ListNode {
2
+ * public var val: Int
3
+ * public var next: ListNode?
4
+ * public init(_ val: Int) {
5
+ * self.val = val
6
+ * self.next = nil
7
+ * }
8
+ * }
9
+ */
10
+
11
+ class Solution {
12
+ func reversePrint( _ head: ListNode ? ) -> [ Int ] {
13
+ var stack = [ Int] ( )
14
+ var current = head
15
+ while let node = current {
16
+ stack. append ( node. val)
17
+ current = node. next
18
+ }
19
+
20
+ return stack. reversed ( )
21
+ }
22
+ }
You can’t perform that action at this time.
0 commit comments