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的更多相关文章
- 344. Reverse String【easy】
344. Reverse String[easy] Write a function that takes a string as input and returns the string rever ...
- [LeetCode] Reverse String 翻转字符串
Write a function that takes a string as input and returns the string reversed. Example: Given s = &q ...
- LeetCode Reverse String
原题链接在这里:https://leetcode.com/problems/reverse-string/ 题目: Write a function that takes a string as in ...
- Nim Game,Reverse String,Sum of Two Integers
下面是今天写的几道题: 292. Nim Game You are playing the following Nim Game with your friend: There is a heap o ...
- [CareerCup] 1.2 Reverse String 翻转字符串
1.2 Implement a function void reverse(char *str) in C or C++ which reverses a null-terminated string ...
- 344. Reverse String(C++)
344. Reverse String Write a function that takes a string as input and returns the string reversed. E ...
- [LeetCode] 344 Reverse String && 541 Reverse String II
原题地址: 344 Reverse String: https://leetcode.com/problems/reverse-string/description/ 541 Reverse Stri ...
- [LeetCode] Reverse String II 翻转字符串之二
Given a string and an integer k, you need to reverse the first k characters for every 2k characters ...
- LeetCode Javascript实现 344. Reverse String 292. Nim Game 371. Sum of Two Integers
344. Reverse String /** * @param {string} s * @return {string} */ var reverseString = function(s) { ...
随机推荐
- Spring事务控制和传递性理解
1.在同一类方法间相互调用,如果调用方无事务控制,被调用方有事务控制,则被调用方也无事务 原因:外部经过spring容器调用service的方法事务才生效,service类内部方法间相互调用事务不生效 ...
- Maven 项目中 添加自己的jar包
mvn install:install-file -Dfile=java-bloomfilter-1.0.jar -DgroupId=com.sina -DartifactId=java-bl ...
- ArcGIS模型构建器案例学习-批量删除空要素类地理模型
ArcGIS模型构建器案例学习笔记-批量删除空要素类地理模型 联系方式:谢老师,135-4855-4328,xiexiaokui@qq.com 目的:批量删除记录个数为0的矢量文件 优点:逻辑清晰,不 ...
- 新手C#SQLServer在程序里实现语句的学习2018.08.12
从C#中连接到SQL Server数据库,再通过C#编程实现SQL数据库的增删改查. ado.net提供了丰富的数据库操作,这些操作可以分为三个步骤: 第一,使用SqlConnection对象连接数据 ...
- golang获取IP地址
ip:=this.Ctx.Request.RemoteAddr ip=ip[0:strings.LastIndex(ip, ":")]
- hdoj2859(矩阵DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2859 思路: 第一次碰到这种矩阵上的DP题,想了半天也没想明白.本来想用子矩阵的左上角坐标和右下角坐标 ...
- np.random.random()系列函数
1.np.random.random()函数参数 np.random.random((1000, 20)) 上面这个就代表生成1000行 20列的浮点数,浮点数都是从0-1中随机. 2.numpy.r ...
- SSH(Struts,Spring,Hibernate)和SSM(SpringMVC,Spring,MyBatis)的区别
SSH 通常指的是 Struts2 做前端控制器,Spring 管理各层的组件,Hibernate 负责持久化层. SSM 则指的是 SpringMVC 做前端控制器,Spring 管理各层的组件,M ...
- python事件驱动的小例子
首先我们写一个超级简单的web框架 event_list = [] #这个event_list中会存放所有要执行的类 def run(): for event in event_list: obj = ...
- 性能测试需求分析 业务PV量,响应时间、QPS、TPS
一. 性能测试需求分析 1.1 性能测试需求内容 性能测试需求应包括以下内容: a) 测试场景及用例,用例访问URL: b) 目标接口方法的入参.出参: c) 外部依赖的服务 ...