diff --git "a/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/README.md" index 144b7f9a39139d26c701ef344aecc170a3dfc1e4..a4a0a070910258b01e339eda13216fd2107acf57 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/README.md" @@ -110,6 +110,42 @@ class Solution { } ``` +递归实现: + +```java +/** + * Definition for singly-linked list. + * public class ListNode { + * int val; + * ListNode next; + * ListNode(int x) { val = x; } + * } + */ +class Solution { + public int[] reversePrint(ListNode head) { + List values = new ArrayList(); + printNode(head, values); + + int[] result = new int[values.size()]; + int index = 0; + for (Integer ele : values){ + result[index++] = ele; + } + return result; + } + + private void printNode(ListNode head, List values){ + if (head != null){ + Integer val = head.val; + if (head.next != null){ + printNode(head.next, values); + } + values.add(val); + } + } +} +``` + ### **JavaScript** ```js