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