标签:end mem already pap ipy function pen site str
Given a string, write a function that uses recursion to reverse it.
You MUST use pen and paper or a whiteboard to answer this, no coding allowed!
Hopefully you remember this problem, you‘ve already seen it! The solution is:
def reverse(s): # Base Case if len(s) <= 1: return s # Recursion return reverse(s[1:]) + s[0]
Remember when recursion questions arise, think about the base case and the recursive case. Review the recusion section of the course for review for this problem.
Reverse string using recursion
标签:end mem already pap ipy function pen site str
原文地址:http://www.cnblogs.com/prmlab/p/6961021.html