###题目:翻转一个字符串
###思路:从字符串的最后一位开始,依次取
###实现:伪代码、函数、类实现

#伪代码:

#01
string=s
New_s=""
for i in range(1,len(string)+1):
New_s+=string[-i]

#02
string=s
New_s=""
def  reversal_str(n):
    New_s +=string[n]

return reversal_str(n-1)

###函数实现:

def rerversal_handler01(string):
New_s=str()
if string !=None:
try:
for i in range(1,len(string)+1):
New_s+=string[-i]
except TypeError as e:
print(e) finally:
print(New_s)

###类实现:

class ReversalStr:
def __init__(self,string):
self.t=string
self.New_s="" def reversal_str(self,n):
self.New_s +=self.t[n]
if n>=0:
return self.reversal_str(n-1)
else:
print(self.New_s)

《Craking the Coding interview》python实现---02的更多相关文章

  1. 《Craking the Coding interview》python实现---01

    ###题目:给定一个字符串,判断其中是否有重复字母###思路:将重复的字符放入到list中,并进行计数统计###实现:伪代码.函数.类实现###伪代码:string=s #给定的字符串list=[] ...

  2. Craking the coding interview 面试题:完美随机洗牌

    给定一个序列,随机打乱这个序列,新产生的序列和任意一个序列产生的可能性是一样的,就是所谓的完美随机洗牌. 看下面的运行结果: 上面第一列是原数列,下面一行是新产生的打乱的数列. 基本思想:如果n-1个 ...

  3. Python Coding Interview

    Python Coding Interview Python Advanced Use enumerate() to iterate over both indices and values Debu ...

  4. Cracking the coding interview目录及资料收集

    前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...

  5. Python学习02 列表 List

    Python学习02 列表 List Python列表 List Python中的列表(List)用逗号分隔,方括号包围(comma-separated values (items) between ...

  6. A few things to remember while coding in Python.

    A few things to remember while coding in Python. - 17 May 2012 - UPDATE: There has been much discuss ...

  7. Cracking the coding interview

    写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...

  8. 转:Top 10 Algorithms for Coding Interview

    The following are top 10 algorithms related concepts in coding interview. I will try to illustrate t ...

  9. Cracking the coding interview 第一章问题及解答

    Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...

随机推荐

  1. 洛谷T47092 作业_简单状压动归

    只要注意一下细节就毫无难点了,简简单单状态压缩即可. Code: #include<cstdio> #include<algorithm> using namespace st ...

  2. C语言基础 (4) 原码反码补码与数据类型

    1.回顾 使用gcc编译代码 gcc hello.c -o hello windows下编译代码 C语言编译步骤: 预处理(头文件展开,干掉注释) gcc -E hello.c -o hello.i ...

  3. node工具是是什么东西

    Node到底是个啥? Node是一个服务器端JavaScript解释器,可是真的以为JavaScript不错的同学学习Node就能轻松拿下,那么你就错了,总结:水深不深我还不知道,不过确实不浅 最近写 ...

  4. [USACO18OPEN] Multiplayer Moo (并查集+维护并查集技巧)

    题目大意:给你一个N*N的棋盘,棋盘上每个点都有一个权值 第一问求一个权值形成的最大联通块中点的数量 第一问求两个权值共同形成的最大联通块中点的数量 提供一种并查集的做法:(感谢大佬们的题解)第一问把 ...

  5. hive用mysql作元数据代替默认derby的hive-site.xml配置

    <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://s ...

  6. react中的跨域问题

    react中的跨域问题

  7. js中的json操作

    js中的json操作 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,是理想的数据交换格式.同时,JSON是 JavaScr ...

  8. 【codeforces 500E】New Year Domino

    [题目链接]:http://codeforces.com/problemset/problem/500/E [题意] 有n个多米诺骨牌; 你知道它们的长度; 然后问你,如果把第i骨牌往后推倒,然后要求 ...

  9. COGS——T 886. [USACO 4.2] 完美的牛栏

    http://www.cogs.pro/cogs/problem/problem.php?pid=886 ★★☆   输入文件:stall4.in   输出文件:stall4.out   简单对比时间 ...

  10. 110_leetcode_Best Time to Buy and sell Stock II

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...