当前位置:网站首页>[LeetCode] 反转字符串中的单词 III【557】
[LeetCode] 反转字符串中的单词 III【557】
2022-07-02 22:06:00 【山茶花开时。】
问题: 给定一个字符串s,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序
示例1
输入: s = "Let's take LeetCode contest"
输出: "s'teL ekat edoCteeL tsetnoc"
示例2
输入: s = "God Ding"
输出: "doG gniD"
Python3解题
# 解法1
def reverseWords(s):
res = []
arrs = s.split(" ")
for val in arrs:
new_val = val[::-1]
res.append(new_val)
last_res = ' '.join(res)
return last_res
reverseWords("Let's take LeetCode contest")
reverseWords("God Ding")
涉及知识点:
[Python] join()方法https://blog.csdn.net/Hudas/article/details/122850092[Python] split()方法
https://blog.csdn.net/Hudas/article/details/122849811
边栏推荐
- Learn computer knowledge from scratch
- 牛客网:最大子矩阵
- Using emqx cloud to realize one machine one secret verification of IOT devices
- Market Research - current market situation and future development trend of aircraft audio control panel system
- 建立自己的网站(22)
- Developers share | HLS and skillfully use Axi_ Customize the master bus interface instructions and improve the data bandwidth - area exchange speed
- [shutter] shutter application life cycle (foreground state resumed | background state paused | inactive | component separation state detached)
- I admire that someone explained such an obscure subject as advanced mathematics so easily
- Market Research - current market situation and future development trend of marine wet exhaust hose
- SimpleITK使用——4. 奇怪的問題
猜你喜欢
New feature of go1.18: trylock, which has been tossed n times
NC50965 Largest Rectangle in a Histogram
Developers share | HLS and skillfully use Axi_ Customize the master bus interface instructions and improve the data bandwidth - area exchange speed
Get off work on time! Episode 6 of Excel Collection - how to split and count document amounts
图形视图框架
Utilisation de simpletk - 4. Question étrange
wait解决僵尸进程
[ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)
Commodity information management system (C language document version)
NC50965 Largest Rectangle in a Histogram
随机推荐
傑理之修改不需要長按開機功能【篇】
Using emqx cloud to realize one machine one secret verification of IOT devices
20220702 how do programmers build knowledge systems?
PMP项目整合管理
[001] [arm-cortex-m3/4] internal register
Build your own website (22)
How should programmers write logs
[C question set] of V
《乔布斯传》英文原著重点词汇笔记(九)【 chapter seven】
Market Research - current market situation and future development trend of intravenous injection (IV) bottles
杰理之如何测试按键的误触率【篇】
杰理之内置短按再长按,不管长按多长时间都是短按【篇】
Learn computer knowledge from scratch
Reading experience of just because
SimpleITK使用——4. 奇怪的問題
[ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)
图形视图框架
What is the'function'keyword used in some bash scripts- What is the 'function' keyword used in some bash scripts?
[QT] QT multithreading development - reentrancy and thread safety
数学建模——图与网络模型及方法(一)