Python [Leetcode 344]Reverse String
题目描述:
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
解题思路:
见代码。
代码如下:
class Solution(object):
def reverseString(self, s):
"""
:type s: str
:rtype: str
"""
t = list(s)
l = len(t)
for i, j in zip(range(l - 1, 0, -1), range(l // 2)):
t[i], t[j] = t[j], t[i] return ''.join(t)
Python [Leetcode 344]Reverse String的更多相关文章
- [LeetCode] 344 Reverse String && 541 Reverse String II
原题地址: 344 Reverse String: https://leetcode.com/problems/reverse-string/description/ 541 Reverse Stri ...
- Leetcode#344. Reverse String(反转字符串)
题目描述 编写一个函数,其作用是将输入的字符串反转过来. 示例 1: 输入: "hello" 输出: "olleh" 示例 2: 输入: "A man ...
- leetcode 344. Reverse String 、541. Reverse String II 、796. Rotate String
344. Reverse String 最基础的旋转字符串 class Solution { public: void reverseString(vector<char>& s) ...
- LeetCode 344. Reverse String(反转字符串)
题目描述 LeetCode 344. 反转字符串 请编写一个函数,其功能是将输入的字符串反转过来. 示例 输入: s = "hello" 返回: "olleh" ...
- [LeetCode] 344. Reverse String 翻转字符串
Write a function that reverses a string. The input string is given as an array of characters char[]. ...
- Leetcode 344 Reverse String 字符串处理
题意:反转字符串,用好库函数. class Solution { public: string reverseString(string s) { reverse(s.begin(),s.end()) ...
- LeetCode 344. Reverse String
Problem: Write a function that takes a string as input and returns the string reversed. Example: Giv ...
- (字符串 数组 递归 双指针) leetcode 344. Reverse String
Write a function that reverses a string. The input string is given as an array of characters char[]. ...
- 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) { ...
随机推荐
- 深入浅出ES6(十四):let和const
作者 Jason Orendorff github主页 https://github.com/jorendorff 回溯到1995年,当Brendan Eich在设计第一版JavaScript时, ...
- 优雅的python 写排序算法
arr=[] while True: #输入数据 当输入q结束 a=raw_input() if a=="q": break arr.append(int(a)) s=len(ar ...
- Xamarin for Visual Studio 3.11.666 Beta版 破解补丁
注意:本版本是 Beta 版 现已推送到稳定频道 前提概要 全新安装请参考 安装 Xamarin for Visual Studio. 最新稳定版请参考 Xamarin for Visual St ...
- 解析Java中静态变量与实例变量的区别
java类的成员变量有俩种:一种是被static关键字修饰的变量,叫类变量或者静态变量:另一种没有static修饰,为实例变量. 在语法定义上的区别:静态变量前要加static关键字,而实例 ...
- C#中out的用法
out的用法 out 关键字会导致参数通过引用来传递.这与 ref 关键字类似,不同之处在于 ref 要求变量必须在传递之前进行初始化.若要使用 out 参数,方法定义和调用方法都必须显式使用 out ...
- Linux Tomcat必须知道的命令
查看java相关的进程号:ps -ef|grep java 杀死进程:kill -s 9(进程号,9优先级最高) 预启动tomcat: ./catalina.sh run (可查看启动状态) 启动to ...
- Centos环境下部署游戏服务器-iptables
简介: 图1 Centos做为服务器级操作系统,防火墙是不可缺少的.防火墙的主要功能为控制进出网络包,防火墙就如小区门卫的工作职责,检查出入小区居民的身份,如果不符合小区门卫管理条例 ...
- Mysql Workbench 学习
1.安装 http://dev.mysql.com/downloads/tools/workbench/ 选择合适的,下载(以Ubuntu 为例) cd到下载目录,然后sudo dpkg -i wor ...
- linux查看内存
cat /proc/meminfo 查看内存,查看最为准确. cat /proc/cpuinfo 察看CPU情况. dmesg | less 这样也可以看到,不过带太多的其他信息了. top也可 ...
- Centos下修改启动项和网络配置
1.Centos默认是从图形界面启动,需要较多的资源,为了节省资源可以从命令行启动.修改方法如下: /etc/inittab文件,把 代码: id:5:initdefault:这一行,修改成 代码: ...