当前位置:网站首页>【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()])
边栏推荐
猜你喜欢
Solution of Queen n problem
搭建自己的语义分割平台deeplabV3+
搭载TI AM62x处理器,飞凌FET6254-C核心板首发上市!
04_ Stack
Solve the problem of frequent interruption of mobaxterm remote connection
Party History Documentary theme public welfare digital cultural and creative products officially launched
飞凌嵌入式RZ/G2L处理器核心板及开发板上手评测
How to avoid 7 common problems in mobile and network availability testing
How to choose a third-party software testing organization for automated acceptance testing of mobile applications
05_ queue
随机推荐
Engineer evaluation | rk3568 development board hands-on test
Learn the method code example of converting timestamp to uppercase date using PHP
11_Redis_Hyperloglog_命令
03_ Linear table_ Linked list
Bing. Com website
Common English abbreviations for data analysis (I)
【网络安全】网络资产收集
Storage read-write speed and network measurement based on rz/g2l | ok-g2ld-c development board
LeetCode刷题——去除重复字母#316#Medium
13_Redis_事务
21_ Redis_ Analysis of redis cache penetration and avalanche
LeetCode刷题——验证二叉树的前序序列化#331#Medium
Tidb hybrid deployment topology
07_哈希
高考录取分数线爬取
Leetcode question brushing - parity linked list 328 medium
folium地图无法显示的问题,临时性解决方案如下
Data analysis thinking analysis methods and business knowledge - business indicators
02. After containerization, you must face golang
Learn the method code of using PHP to realize the conversion of Gregorian calendar and lunar calendar