首页 > 代码库 > Reverse string using recursion
Reverse string using recursion
On-Site Question 3 - SOLUTION
Question
Given a string, write a function that uses recursion to reverse it.
Requirements
You MUST use pen and paper or a whiteboard to answer this, no coding allowed!
SOLUTION
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]
Notes
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.
Good Job!
Reverse string using recursion
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。