当前位置:网站首页>【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()])
边栏推荐
- I made an istio workshop. This is the first introduction
- 数据分析思维分析方法和业务知识——业务指标
- 微信支付宝账户体系和支付接口业务流程
- LeetCode刷题——去除重复字母#316#Medium
- LeetCode刷题——验证二叉树的前序序列化#331#Medium
- 06_ Stack and queue conversion
- 07_ Hash
- Huffman tree: (1) input each character and its weight (2) construct Huffman tree (3) carry out Huffman coding (4) find hc[i], and get the Huffman coding of each character
- JVM architecture, classloader, parental delegation mechanism
- Engineer evaluation | rk3568 development board hands-on test
猜你喜欢
How to find a sense of career direction
15_ Redis_ Redis. Conf detailed explanation
怎样从微信返回的json字符串中截取某个key的值?
LeetCode刷题——验证二叉树的前序序列化#331#Medium
Application and practice of Jenkins pipeline
Facing the challenge of "lack of core", how can Feiling provide a stable and strong guarantee for customers' production capacity?
6.12 企业内部upp平台(Unified Process Platform)的关键一刻
03_ Linear table_ Linked list
03. Preliminary use of golang
Kibana basic operation
随机推荐
损失函数与正负样本分配:YOLO系列
Common English abbreviations for data analysis (I)
11_ Redis_ Hyperloglog_ command
12_ Redis_ Bitmap_ command
Principles, language, compilation, interpretation
哈夫曼树:(1)输入各字符及其权值(2)构造哈夫曼树(3)进行哈夫曼编码(4)查找HC[i],得到各字符的哈夫曼编码
Tidb environment and system configuration check
Kibana basic operation
Leetcode question brushing - parity linked list 328 medium
How to conduct TPC-C test on tidb
07_ Hash
Recommended configuration of tidb software and hardware environment
Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!
How to find a sense of career direction
How to write sensor data into computer database
Bing.com網站
14_Redis_乐观锁
How does the computer set up speakers to play microphone sound
How to solve the problem of database content output
飞凌嵌入式RZ/G2L处理器核心板及开发板上手评测