title | date | draft | tags | categories | |||
---|---|---|---|---|---|---|---|
算法4 Java解答 1.2.07 |
2019-02-22 07:35:22 +0800 |
false |
|
|
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
}