当前位置:网站首页>[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
边栏推荐
- SimpleITK使用——4. 奇怪的问题
- Radis:Linux上安装Redis(步骤)
- New feature of go1.18: trylock, which has been tossed n times
- I admire that someone explained such an obscure subject as advanced mathematics so easily
- Market Research - current market situation and future development trend of genome editing mutation detection kit
- Phpcms realizes the direct Alipay payment function of orders
- Service visibility and observability
- Meibeer company is called "Manhattan Project", and its product name is related to the atomic bomb, which has caused dissatisfaction among Japanese netizens
- Market Research - current market situation and future development trend of aircraft audio control panel system
- Jerry's modification does not require long press the boot function [chapter]
猜你喜欢

Ransack combined condition search implementation

Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?

Get off work on time! Episode 6 of Excel Collection - how to split and count document amounts

Struct, bit segment, enumeration, union

百度智能云-创建人脸识别应用

Simpleitk use - 4 Strange question

Kubernetes resource object introduction and common commands (4)

Perceptron model and Application

#include errors detected. Please update your includePath.

Source code analysis - lightweight asynchronous crawler framework Ruia
随机推荐
杰理之充电拔出,无法触摸开机【篇】
New feature of go1.18: trylock, which has been tossed n times
Market Research - current market situation and future development trend of aircraft front wheel steering system
UE4 游戏架构 学习笔记
Meibeer company is called "Manhattan Project", and its product name is related to the atomic bomb, which has caused dissatisfaction among Japanese netizens
Market Research - current market situation and future development trend of genome editing mutation detection kit
Objects and object variables
《乔布斯传》英文原著重点词汇笔记(九)【 chapter seven】
20220702 how do programmers build knowledge systems?
附加:【登录信息存储】与【登录状态校验】;(包括:总结了到目前为止,有关【登录信息存储】与【登录状态校验】的所有内容;)
Market Research - current market situation and future development trend of third-party data platform
建立自己的网站(22)
Market Research - current situation and future development trend of carob chocolate market
php优化foreach中的sql查询
Dynamic memory allocation (malloc calloc realloc free)
送给即将工作的自己
解决 excel 文件上传时更改选中的文件出现错误net::ERR_UPLOAD_FILE_CHANGED
【ODX Studio编辑PDX】-0.1-如何快速查看各Variant变体间的支持的诊断信息差异(服务,Sub-Function...)
【AUTOSAR-DCM】-4.3-UDS $22和$2E服务如何读取和写入NVM数据
Market Research - current situation and future development trend of marine clutch Market