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) { ...
随机推荐
- 25. LiveBos调用class实例
var v= ABS_LOADBEAN('com.apex.mmsqljdbc.TestJDBC');var date=ABS_SQLVALUE("select to_char(?,'yyy ...
- 自定义BeanUtils
package com.icil.booking.service.util; import java.math.BigDecimal; import java.text.ParseException; ...
- leetcode50
public class Solution { public double MyPow(double x, int n) { return Math.Pow(x, (double)n); } }
- ios 确定文字所占矩形框大小
labelFrame.size = [self.label.text sizeWithFont:self.label.font constrainedToSize:CGSizeMake(self.la ...
- tensorflow笔记之滑动平均模型
tensorflow使用tf.train.ExponentialMovingAverage实现滑动平均模型,在使用随机梯度下降方法训练神经网络时候,使用这个模型可以增强模型的鲁棒性(robust),可 ...
- 【转】Luajit-2.1.0-beta1的发布和生成arm64用bytecode的解脱
来自:Luajit-2.1.0-beta1的发布和生成arm64用bytecode的解脱 前情提要:由于苹果要求2015年2月1日上架的新app必须支持64位的arm64,旧的app也得在6月1日支持 ...
- 离线安装Cloudera Manager 5和CDH5
关于CDH和Cloudera Manager CDH (Cloudera's Distribution, including Apache Hadoop),是Cloudera 完全开源的Hadoop ...
- Linux就业技术指导(七):游戏类运维重点流程解析
一,某游戏公司例行上线与更新流程示例 例行维护/更新流程 1.1 更新前天 提前确认好要更新的是什么,更新会有人通知你,一般是运营人员 比如:我们明天做什么什么更新 1.2 第2天更新 一般固定点更新 ...
- HTML5 画图--文字
1:html <div style="margin:0 auto;width:794px;height:1123px"> <canvas id="myC ...
- bed文件格式解读
1)BED文件 BED 文件(Browser Extensible Data)格式是ucsc 的genome browser的一个格式 ,提供了一种灵活的方式来定义的数据行,以用来描述注释信息.BED ...