leetcode-344. Reverse String 字符串翻转,切片的用法
来源:互联网 发布:Ubuntu sambaclient 编辑:程序博客网 时间:2024/06/05 17:36
题目:
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
反转字符串,这个题python只用了一句话:
class Solution(object):
def reverseString(self, s):"""
:type s: str
:rtype: str
"""
return s[::-1]
笔记:
切片的概念:
python可对list、tuple、string的数据类型进行切片,即可获取list、tuple、string的部分元素,切片方法非常灵活。
以string类型为例:s=[abcdefg]
顺序截取:
起始位置:终止位置:每隔多少个获取一个字符 当某个位置省略时,用:号代替
例如:
逆序截取:
记住倒数第一个元素的索引-1:
终止位置:起始位置 当某个位置省略时,用:号代替
0 0
- leetcode-344. Reverse String 字符串翻转,切片的用法
- LeetCode 344. Reverse String(字符串翻转)
- LeetCode 344: Reverse String (字符串翻转)
- Reverse String 翻转字符串
- 翻转(reverse)字符串(string)的所有方法
- leetcode 151. Reverse Words in a String 字符串 翻转
- LeetCode 541. Reverse String II (字符串翻转)
- Reverse Words in a String 翻转一个字符串里的单词顺序 @LeetCode
- LeetCode OJ 之 Reverse Words in a String (翻转字符串的单词)
- 【leetcode】 Reverse Vowels of a String(翻转字符串中出现的元音字母)
- Python - 翻转(reverse)字符串(string)的所有方法 详解
- 翻转(reverse)字符串(string)的所有方法 详解
- Reverse Words in a String 翻转字符串
- JavaScript实现-字符串翻转-Reverse a String
- Python翻转字符串(reverse string)详解
- JavaScript实现-字符串翻转-Reverse a String
- LeetCode----344. Reverse String 字符串反转
- LeetCode oj 344. Reverse String(字符串)
- AndroidStudio buildgradle升级导致的兼容性问题
- 父类引用指向子类对象
- sql:decode()的用法
- JS正则密码验证
- 双线性插值算法原理及其实现
- leetcode-344. Reverse String 字符串翻转,切片的用法
- 云计算术语: Fabric & Instance
- 输出任意网站的html到本地
- RedHat Linux 安装g++环境
- Lua语法小贴士(二)string库
- dd命令使用详解
- CSS之使用css布局
- 消息系统扩容处理
- 测试经验分享