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) { ...
随机推荐
- jmeter学习预热
对jmeter有些兴趣,最近想抽点时间熟悉下,个人熟悉某个工具的方法: 1.官网http://jmeter.apache.org/,一般官网会有Tutorials或者Getting Started之类 ...
- shell如何自动输入密码
shell如何自动输入密码 http://linux.ctocio.com.cn/171/12162171.shtml
- http://www.cnblogs.com/TankXiao/p/4018219.html
http://www.cnblogs.com/TankXiao/p/4018219.html
- RHadoop计算平台搭建
原创文章,转载请注明: 转载自www.cnblogs.com/tovin/p/3824554.html 本文基于CentOS6.4系统介绍基于RHadoop平台的搭建,Hadoop的搭建可以参考ht ...
- ios 监听app从后台恢复到前台
正常情况下,在AppDelegate中实现下面两个方法,能够监听从后台恢复到前台 [cpp] - (void)applicationDidEnterBackground:(UIApplication ...
- IDL---ENVI
ENVI;启动envi file=envi_pickfile();选择文件dialog,返回值就为file ENVI_OPEN_FIle,file,r_fid=fid;根据文件名打开file,并且返回 ...
- 286. Walls and Gates
题目: You are given a m x n 2D grid initialized with these three possible values. -1 - A wall or an ob ...
- CentOS防火墙操作实例(启动、停止、开、闭端口)
注:防火墙的基本操作命令: 查询防火墙状态: [root@localhost ~]# service iptables status<回车> 停止防火墙: [root@localh ...
- Java:日历类、日期类、数学类、运行时类、随机类、系统类
一:Calendar类 java.util 抽象类Calendar 1.static Calendar getInstance()使用默认时区和语言环境获得一个日历. 2. int get(int ...
- c# 文件简繁体转换
C# 文件简繁体转换 简繁体转换: 方案一: 准确性高,耗性能 方案二: 准确性低,效率高 1 using Microsoft.International.Converters.Tradition ...