当前位置:网站首页>【LeetCode】577-反转字符串中的单词 III
【LeetCode】577-反转字符串中的单词 III
2022-07-02 12:09:00 【酥酥~】
给定一个字符串 s ,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序。
示例 1:
输入: s = “Let’s take LeetCode contest”
输出: “s’teL ekat edoCteeL tsetnoc”
示例 2:
输入: s = “God Ding”
输出: “doG gniD”
提示:
- 1 <= s.length <= 5 * 104
- s 包含可打印的 ASCII 字符。
- s 不包含任何开头或结尾空格。
- s 里 至少 有一个词。
- s 中的所有单词都用一个空格隔开。
#字符串分割,逐个反转,合并
class Solution(object):
def reverseWords(self, s):
return " ".join([word[::-1] for word in s.split()])
边栏推荐
猜你喜欢
14_Redis_乐观锁
N皇后问题的解决
LeetCode刷题——统计各位数字都不同的数字个数#357#Medium
Semantic segmentation learning notes (1)
6.12 企业内部upp平台(Unified Process Platform)的关键一刻
Leetcode skimming -- sum of two integers 371 medium
10_ Redis_ geospatial_ command
微信支付宝账户体系和支付接口业务流程
6.12 critical moment of Unified Process Platform
Practice of compiling principle course -- implementing an interpreter or compiler of elementary function operation language
随机推荐
Principles, language, compilation, interpretation
Leetcode question brushing - parity linked list 328 medium
怎样从微信返回的json字符串中截取某个key的值?
How to test tidb with sysbench
yolo格式数据集处理(xml转txt)
Facing the challenge of "lack of core", how can Feiling provide a stable and strong guarantee for customers' production capacity?
02. After containerization, you must face golang
04_ 栈
15_Redis_Redis.conf详解
Yolo format data set processing (XML to txt)
4. Data splitting of Flink real-time project
How does the computer set up speakers to play microphone sound
高考录取分数线爬取
18_Redis_Redis主从复制&&集群搭建
Topology architecture of the minimum deployment of tidb cluster
I made an istio workshop. This is the first introduction
微信支付宝账户体系和支付接口业务流程
. Net again! Happy 20th birthday
士官类学校名录
07_ Hash