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) { ...
随机推荐
- 制作类似DataGrid自定义控件
首先看一下.net自带的DataGrid,想想如何应该怎样才能实现那样的展现形式. 1)需要以网格形式显示内容. 2)网格的宽度.高度可以定义. 3)可以显示滚动条. 4)单击可以选中某个单元格. 当 ...
- c#知识库同步的总结
C#知识库下载地址: http://www.51aspx.com/Code/FileCollector 新版下载地址:http://pan.baidu.com/s/1P3Hk 对于这一款平时用来收集知 ...
- android自动化环境搭建
android自动化环境安装指南 1.appium相关安装(eclipse下)见http://www.cnblogs.com/wangcp-2014/p/5717589.html参考selenium的 ...
- Android Non-UI to UI Thread Communications(Part 3 of 5)
Original:http://www.intertech.com/Blog/android-non-ui-to-ui-thread-communications-part-3-of-5/ Conti ...
- 一起学习redis源码
redis的一些介绍,麻烦阅读前面的几篇文章,想对redis的详细实现有所了解,强力推荐<redis设计与实现>(不仅仅从作者那儿学习到redis的实现,还有项目的管理.思想等,作者可能比 ...
- Hive常用的SQL命令操作
Hive提供了很多的函数,可以在命令行下show functions罗列所有的函数,你会发现这些函数名与mysql的很相近,绝大多数相同的,可通过describe function functionN ...
- SPRING IN ACTION 第4版笔记-第十章Hitting the database with spring and jdbc-003-四种方式获取DataSource
一.概述 1.Spring offers several options for configuring data-source beans in your Spring application, i ...
- Data Flow ->> Merge
Merge组件的作用和Union All很相似,就是把两个输入源的结果集合并成一个.但是不同之处在于: 1)Merge输入的结果集需要先经过排序(这点表示怀疑) 2)Merge对于输入的两个结果集的数 ...
- C# 公关类(全)
http://tool.sufeinet.com/CodePreview/CodeView.aspx?action=view&file=FTP/FTPClient.cs
- dojo 四 类的构造函数和父方法的调用
与java类一样,在Dojo里也可以定义constructor 构造函数,在创建一个实例时可以对需要的属性进行初始化.//定义一个类Mqsy_yj var Mqsy_YJ = declare(null ...