From 577223059b6395ecdb5ed0242b9047a1dc8a512f Mon Sep 17 00:00:00 2001 From: hongyiheng Date: Mon, 9 Aug 2021 10:41:39 +0800 Subject: [PATCH] feat: add java solution to lcof2 problem:No.24 reverseList --- .../README.md" | 12 +++++++++++- .../Solution.java" | 11 +++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 "lcof2/\345\211\221\346\214\207 Offer II 024. \345\217\215\350\275\254\351\223\276\350\241\250/Solution.java" diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 024. \345\217\215\350\275\254\351\223\276\350\241\250/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 024. \345\217\215\350\275\254\351\223\276\350\241\250/README.md" index f7afa5312c37b..b32d180481b96 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 024. \345\217\215\350\275\254\351\223\276\350\241\250/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 024. \345\217\215\350\275\254\351\223\276\350\241\250/README.md" @@ -70,7 +70,17 @@ ```java - +class Solution { + public ListNode reverseList(ListNode head) { + if(head == null || head.next == null){ + return head; + } + ListNode res = reverseList(head.next); + head.next.next = head; + head.next = null; + return res; + } +} ``` ### **...** diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 024. \345\217\215\350\275\254\351\223\276\350\241\250/Solution.java" "b/lcof2/\345\211\221\346\214\207 Offer II 024. \345\217\215\350\275\254\351\223\276\350\241\250/Solution.java" new file mode 100644 index 0000000000000..43a1db7a95139 --- /dev/null +++ "b/lcof2/\345\211\221\346\214\207 Offer II 024. \345\217\215\350\275\254\351\223\276\350\241\250/Solution.java" @@ -0,0 +1,11 @@ +class Solution { + public ListNode reverseList(ListNode head) { + if(head == null || head.next == null){ + return head; + } + ListNode res = reverseList(head.next); + head.next.next = head; + head.next = null; + return res; + } +} \ No newline at end of file