Recursive String Reverse Complexity
What is the time complexity of the following recursive reverse method?
public String reverse(String s) {
if (s.length() <= 1) {
return s;
}
return reverse(s.substring(1)) + s.charAt(0);
}
A
O(n log n)
B
O(n)
C
O(n^2)
D
O(2^n)
Question Leaderboard
Not enough data yet to show leaderboard.
