leetcode 151 Reverse Words in a String (python)
leetcode 151 Reverse Words in a String
题目描述:
Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue",
return "blue is sky the".
python代码:
class Solution(object):def reverseWords(self, s):""":type s: str:rtype: str"""rs=s[::-1] #将整个字符串反转l=rs.split() #将反转后的字符串通过split()函数进行分割,产生的单词发在列表l中ls=[word[::-1] for word in l] #使用列表解析,反转列表l中的每一个单词return ' '.join(ls) #使用join()函数,将列表ls中的单词,通过空格连接成一个字符串
(完)
leetcode 151 Reverse Words in a String (python)相关推荐
- LeetCode 151. Reverse Words in a String
151. Reverse Words in a String Given an input string, reverse the string word by word. For example, ...
- leetcode 557. Reverse Words in a String III 、151. Reverse Words in a String
557. Reverse Words in a String III 最简单的把空白之间的词反转 class Solution { public:string reverseWords(string ...
- leetcode day1 -- Reverse Words in a String Evaluate Reverse Polish Notation Max Points on a Li
以前从来没做过什么oj,发现做oj和在本地写代码或者纸上写差别还是很大的,觉得今天开始刷oj,特此记录一下. 1.Reverse Words in a String Given an input st ...
- Python [Leetcode 345]Reverse Vowels of a String
题目描述: Write a function that takes a string as input and reverse only the vowels of a string. Example ...
- LeetCode 345. Reverse Vowels of a String
题目: Write a function that takes a string as input and reverse only the vowels of a string. Example 1 ...
- LeetCode 557. Reverse Words in a String III
题目 : Given a string, you need to reverse the order of characters in each word within a sentence whil ...
- LeetCode OJ1:Reverse Words in a String
问题描述: Given an input string, reverse the string word by word. For example, Given s = "the sky i ...
- Leetcode 345: Reverse Vowels of a String
问题描述: Given a string s, reverse only all the vowels in the string and return it. The vowels are 'a', ...
- 151. Reverse Words in a String
1 题目理解 输入:一个字符串s 规则:一个单词是一串非空字符组成的.单词之间用空格分隔. 输出:将字符串按照单词反转字符串.多余的空格只保留一个. Example 1: Input: s = &qu ...
最新文章
- No.3 clojure 调用 Java
- 花了2周时间收集汇总的大厂面经,节后准备跳槽的看过来!
- 替换ExpandableListView右边箭头Group Indicator(小图标)
- 数据结构与算法之二叉树的先序遍历,中序遍历,后序遍历
- ORACLE基础应用学习-- 各种故障的恢复方法总结
- 【剑指offer】面试题32 - II:从上到下打印二叉树 II(Java)
- 重构随笔——重构的原则
- minio 搭建blob
- Kafka AKHQ 安装部署
- matlab nist接口文件,Matlab调用refprop教程说明
- 水晶报表客户机电脑报错“CrystalDecisions.CrystalReports.Engine.ReportDocument”
- 机器学习实战(SVM)
- 安装此计算机程序代码18,我安装VS15,运行程序代码的时候显示的是计算机丢失msv...
- Scratch编程入门
- 工业4.0,智能制造和大规模定制
- 昆山花桥房都要上万 上海买家占9成“江山”
- 人生性格、爱情与酒场哲学
- Unity3D 中LookAt()方法
- Java基础(一)Java语言概述及入门
- 前端低代码平台腾讯云微搭使用文档