当前位置:网站首页>[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
边栏推荐
- PHP微信抢红包的算法
- SimpleITK使用——4. 奇怪的問題
- Unity3d learning notes 4 - create mesh advanced interface
- wait解决僵尸进程
- kubernetes 使用主机名将 pod 分配在指定节点上
- 【ODX Studio编辑PDX】-0.1-如何快速查看各Variant变体间的支持的诊断信息差异(服务,Sub-Function...)
- Simpleitk use - 4 Strange question
- Socket socket c/s end process
- [C question set] of V
- Perceptron model and Application
猜你喜欢
随机推荐
电商系统微服务架构
杰理之内置关机电流 1.2uA,之后不能长按开机【篇】
[shutter] shutter application theme (themedata | dynamic modification theme)
杰理之快速触摸不响应问题【篇】
Jerry's modification does not require long press the boot function [chapter]
[C question set] of V
Source code analysis - lightweight asynchronous crawler framework Ruia
Introduction to database system Chapter 1 short answer questions - how was the final exam?
Socket套接字C/S端流程
New feature of go1.18: introduce new netip Network Library
PHP implements querying the data matching the date of birth according to the entered age
NC50965 Largest Rectangle in a Histogram
[error record] the flutter reports an error (could not read script 'xxx\flutter\u tools\gradle\app\u plugin\u loader.gradle')
Notes on key vocabulary of the original English book biography of jobs (IX) [chapter seven]
`${}`的用法
[shutter] shutter gesture interaction (small ball following the movement of fingers)
'when to use const char * and when to use const char []' - when to use const char * and when to use const char []
Simpleitk use - 3 Common operations
Using emqx cloud to realize one machine one secret verification of IOT devices
C language, to achieve three chess games