Code Signal_练习题_alphabeticShift
Given a string, replace each its character by the next one in the English alphabet (z would be replaced by a).
Example
For inputString = "crazy", the output should bealphabeticShift(inputString) = "dsbaz".
我的解答:
def alphabeticShift(inputString):
l = []
for x in inputString:
l.append(x)
for i in range(len(inputString)):
if l[i] == 'z':
l[i] = 'a'
else:
l[i] = chr(ord(l[i])+1)
return ''.join(l)
def alphabeticShift(s):
return "".join(chr((ord(i)-96)%26+97) for i in s)
膜拜大佬
Code Signal_练习题_alphabeticShift的更多相关文章
- Code Signal_练习题_digitDegree
Let's define digit degree of some positive integer as the number of times we need to replace this nu ...
- Code Signal_练习题_Knapsack Light
You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the ...
- Code Signal_练习题_growingPlant
Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed ...
- Code Signal_练习题_arrayMaxConsecutiveSum
Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...
- Code Signal_练习题_differentSymbolsNaive
Given a string, find the number of different characters in it. Example For s = "cabca", th ...
- Code Signal_练习题_firstDigit
Find the leftmost digit that occurs in a given string. Example For inputString = "var_1__Int&qu ...
- Code Signal_练习题_extractEachKth
Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6 ...
- Code Signal_练习题_stringsRearrangement
Given an array of equal-length strings, check if it is possible to rearrange the strings in such a w ...
- Code Signal_练习题_absoluteValuesSumMinimization
Given a sorted array of integers a, find an integer x from a such that the value of abs(a[0] - x) + ...
随机推荐
- Python数据结构:栈 队列
栈,队列的特性: 1.栈(stacks)是一种只能通过访问其一端来实现数据存储与检索的线性数据结构,具有后进先出(last in first out,LIFO)的特征 2.队列(queue)是一种具有 ...
- mysql基础知识(2)
十 一.计算字段 计算字段通常需要使用 AS 来取别名,否则输出的时候字段名为计算表达式 select col1*col2 as col12 from mytable concat() 用于连接两个字 ...
- 【Canal源码分析】数据传输协议
Canal的数据传输有两块,一块是进行binlog订阅时,binlog转换为我们所定义的Message,第二块是client与server进行TCP交互时,传输的TCP协议. 一.EntryProto ...
- Zookeeper--0300--java操作Zookeeper,临时节点实现分布式锁原理
删除Zookeeper的java客户端有 : 1,Zookeeper官方提供的原生API, 2,zkClient,在原生api上进行扩展的开源java客户端 3, 一.Zookeeper原生API ...
- Android开发艺术探索学习笔记(六)
第六章 Android的Drawable Drawable的优点:使用简单,比自定义view的成本要低:非图片类型的Drawable占用空间小,有利于减小APK安装包的大小. 6.1Drawable ...
- Toast优化,解决频繁点击多次出现
日常用到Taost的机会很多,用就大家都会用,但是直接使用时,频繁点击Toast就会频繁出现,点击多少次就出现多少次,如果你不在页面的生命周期相应位置cancel掉Toast的话,即使退出了页面也是会 ...
- kafka-java客户端连接
使用java客户端, kafkaproducer, kafkaconsumer进行kafka的连接 注: 0.10 版本之后, 连接kafka只需要brokerip即可, 不需要zookeeper的信 ...
- Java集合——HashMap,HashTable,ConcurrentHashMap区别
Map:“键值”对映射的抽象接口.该映射不包括重复的键,一个键对应一个值. SortedMap:有序的键值对接口,继承Map接口. NavigableMap:继承SortedMap,具有了针对给定搜索 ...
- CentOS 7下搭配简单的C语言开发环境
在CentOS 7下安装gcc,gcc是编译和运行C语言的工具, 安装命令: yum install gcc 中途如果有询问则输入y 安装成功后,通过以下命令 gcc --version 来查看安装的 ...
- SpringMVC之表单校验
SpringMVC已经实现了对Java校验API(JSR-303)的支持,通过使用该API可以实现对数据的校验.要使用SpringMVC的Java校验API并不需要任何配置,只要引入其实现即可.本文使 ...