I can't understand this recursive method as the return method doesn't seem to add the charAt(0) method per run.
Suppose you were given a method that reverses a String (it is correct):
public String reverseString(String s) {
if (s.length() <= 1)
return s;
return reverseString(s.substring(1)) + s.charAt(0);
}
EDIT: I now understand:
- rs(Hello)
- rs(ello) + H
- (rs(llo) + e) + H
- ((rs(lo) + l) + e) + H
- (((rs(o) + l) + l) + e) + H
- o + l + l + e + H