当前位置:网站首页>[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
边栏推荐
- Struct, bit segment, enumeration, union
- Developers share | HLS and skillfully use Axi_ Customize the master bus interface instructions and improve the data bandwidth - area exchange speed
- Market Research - current market situation and future development trend of aircraft front wheel steering system
- 杰理之充电拔出,无法触摸开机【篇】
- Web side defense Guide
- PMP项目整合管理
- PHP optimizes SQL queries in foreach
- Socket套接字C/S端流程
- Try to get property'num for PHP database data reading_ rows' of non-object?
- Notes on key vocabulary of the original English book biography of jobs (IX) [chapter seven]
猜你喜欢

Struct, bit segment, enumeration, union

#include errors detected. Please update your includePath.

Developers share | HLS and skillfully use Axi_ Customize the master bus interface instructions and improve the data bandwidth - area exchange speed

20220702 how do programmers build knowledge systems?

Based on asp Net (used mobile phone sales management system) +asp Net+c # language +vs2010+ database can be used for course design and post design learning

Hanoi Tower problem

图形视图框架

Share how to make professional hand drawn electronic maps
![[shutter] shutter opens a third-party application (url|launcher plug-in search and installation | url| launcher plug-in official example | open browser | open a third-party application)](/img/f7/cb41d159e5c5ef3f4f1b9468d52ccc.jpg)
[shutter] shutter opens a third-party application (url|launcher plug-in search and installation | url| launcher plug-in official example | open browser | open a third-party application)

SimpleITK使用——4. 奇怪的問題
随机推荐
Scrcpy this software solves the problem of sharing mobile screen with colleagues | community essay solicitation
NC50965 Largest Rectangle in a Histogram
电商系统微服务架构
New feature of go1.18: trylock, which has been tossed n times
Pointer array parameter passing, pointer parameter passing
[QT] QT multithreading development - four methods to realize multithreading design
图形视图框架
UE4 游戏架构 学习笔记
Socket socket c/s end process
[micro service sentinel] rewrite Sentinel's interface blockexceptionhandler
Oracle-PL/SQL编程
Source code analysis - lightweight asynchronous crawler framework Ruia
Share how to make professional hand drawn electronic maps
Reading experience of just because
送给即将工作的自己
U++ learning notes - relaxation
Market Research - current situation and future development trend of environmental friendly fireworks Market
Market Research - current market situation and future development trend of third-party data platform
SimpleITK使用——4. 奇怪的问题
Oracle cursor