题解 | #字符串变形#
字符串变形
https://www.nowcoder.com/practice/c3120c1c1bc44ad986259c0cf0f0b80e
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param s string字符串
# @param n int整型
# @return string字符串
#
class Solution:
def trans(self , s: str, n: int) -> str:
# write code here
arrStr = s.split(" ")
arrStr.reverse()
returnStr = ""
for i in range(0,len(arrStr)):
if i == len(arrStr) - 1:
returnStr = returnStr + arrStr[i].swapcase()
else:
returnStr = returnStr + arrStr[i].swapcase() + " "
return returnStr
1.先分割字符串,得到数组(split方法)
2.反转数组(reverse方法)
3.遍历数组,进行字符串拼接,同时转换大小写(swapcase方法)
#23届的你们都什么时候入职?#
嘉士伯公司氛围 613人发布
