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的更多相关文章

  1. 344. Reverse String【easy】

    344. Reverse String[easy] Write a function that takes a string as input and returns the string rever ...

  2. [LeetCode] Reverse String 翻转字符串

    Write a function that takes a string as input and returns the string reversed. Example: Given s = &q ...

  3. LeetCode Reverse String

    原题链接在这里:https://leetcode.com/problems/reverse-string/ 题目: Write a function that takes a string as in ...

  4. 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 ...

  5. [CareerCup] 1.2 Reverse String 翻转字符串

    1.2 Implement a function void reverse(char *str) in C or C++ which reverses a null-terminated string ...

  6. 344. Reverse String(C++)

    344. Reverse String Write a function that takes a string as input and returns the string reversed. E ...

  7. [LeetCode] 344 Reverse String && 541 Reverse String II

    原题地址: 344 Reverse String: https://leetcode.com/problems/reverse-string/description/ 541 Reverse Stri ...

  8. [LeetCode] Reverse String II 翻转字符串之二

    Given a string and an integer k, you need to reverse the first k characters for every 2k characters ...

  9. 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) { ...

随机推荐

  1. MYSQL三大范式

    第一范式:确保每列的原子性. 第一范式是最基本的范式. 数据库表中的字段都是单一属性的,不可再分. 只要是关系数据库都满足第一范式 如果每列(或者每个属性)都是不可再分的最小数据单元(也称为最小的原子 ...

  2. maven下载与配置

    转自:https://www.cnblogs.com/jdys/p/3770534.html 1.访问官网:从maven官网下载maven http://maven.apache.org/downlo ...

  3. discuz 修改积分策略( 在周期中添加"每周" )

    在  source/admincp/admincp_credits.php 文件中, ctrl+f 搜索  $lang['setting_credits_policy_cycletype_1'] 处, ...

  4. dir 使用,统计文件数量

    dir /b /a-d | find /v /c "$$$$" >1.log--※ 来源:·水木社区 newsmth.net·[FROM: 125.46.17.*] 今天去水 ...

  5. as3 名称

    加密算法方式: https://www.cnblogs.com/wei2yi/p/3484170.html AES  (Advanced Encryption Standard) DES(Data E ...

  6. 前端-CSS-10-定位

    <!-- 定位有三种: 1.相对定位 2.绝对定位 3.固定定位 这三种定位,每种定位都暗藏玄机,所以我们要一一单讲 position:relative; position:absolute; ...

  7. pip cannot confirm SSL certificate: SSL module is not available

    centos6.8编译安装python2.7之后,使用pip报错:pip cannot confirm SSL certificate: SSL module is not available 解决方 ...

  8. 快速可靠网络传输协议 KCP(转)

    KCP 是一个快速可靠协议,能以比 TCP浪费10%-20%的带宽的代价,换取平均延迟降低30%-40%,且最大延迟降低三倍的传输效果.纯算法实现,并不负责底层协议(如UDP)的收发,需要使用者自己定 ...

  9. HIBERNATE知识复习记录3-关联关系

    先上一张图,关于几种关系映射: 抄一段解释: 基本映射是对一个实体进行映射,关联映射就是处理多个实体之间的关系,将关联关系映射到数据库中,所谓的关联关系在对象模型中有一个或多个引用.关联关系分为上述七 ...

  10. 【转】 关于寄存器ESP和EBP的一些理解

    原文: http://blog.csdn.net/zsJum/article/details/6117043 一直对寄存器ESP和EBP的概念总是有些混淆,查看定义ESP是栈顶指针,EBP是存取堆栈指 ...