Skip to content

Latest commit

 

History

History
41 lines (29 loc) · 594 Bytes

Ex_1_2_07.md

File metadata and controls

41 lines (29 loc) · 594 Bytes
title date draft tags categories
算法4 Java解答 1.2.07
2019-02-22 07:35:22 +0800
false
JAVA
技术
归档

1.2.07

问题:

What does the following recursive function return?

分析:

reverse sequence of string.

  public static String mystery(String s) {
    int N = s.length();
    if (N <= 1)
      return s;
    String a = s.substring(0, N / 2);
    String b = s.substring(N / 2, N);
    return mystery(b) + mystery(a);
  }


  public static void main(String[] args) {
    StdOut.println(mystery("abcde")); // edcba
  }

参考: