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. packert tracer配置路由器

    配置路由器snmp: https://wenku.baidu.com/view/e73c343f0b4c2e3f57276329.html

  2. redhat 7安装CentOS 7 yum源

    http://www.bubuko.com/infodetail-2004218.html http://www.bubuko.com/infodetail-2004218.html ******** ...

  3. sqlserver主从复制

    参考网站: http://www.178linux.com/9079 https://www.cnblogs.com/tatsuya/p/5025583.html windows系统环境进行主从复制操 ...

  4. 8. myeclipse10 svn插件安装

    1.在myeclipse安装目录下找到dropins文件夹,并在下面创建svn文件夹 2. 解压site-1.8.22.zip 3. 4. 5. 6.

  5. Gradle 语法

    参考文章: Gradle学习系列之二——创建Task的多种方法(http://www.cnblogs.com/CloudTeng/p/3417970.html) Gradle基本知识点与常用配置(ht ...

  6. Simple2D-22(重构)纹理池

    以前 Simple2D 使用 TextureManager,现在将它改为 TexturePool (纹理池).主要是负责加载和管理纹理,这次为 TexturePool 添加纹理集的功能,纹理集就是将大 ...

  7. linux c++下载http文件并显示进度<转>

    #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <net ...

  8. 4 python内置函数

    1.内置函数的整体介绍 内置参数官方详解 https://docs.python.org/3/library/functions.html?highlight=built#ascii 2.各内置函数介 ...

  9. WP runtime 获取cookie

    HttpBaseProtocolFilter httpBaseProtocolFilter = new HttpBaseProtocolFilter(); HttpCookieManager http ...

  10. webserive学习记录6-页面请求webservice

    前面都是通过JAVA代码访问webservice服务,下面将介绍通过javascript,jquery访问webservice服务并介绍过过servlet解决跨域问题的方法. 服务端 编写服务代码,解 ...