反转字符串
class Solution:
def reverseString(self, s):
"""
Do not return anything, modify s in-place instead.
"""
for i in range(len(s)//2):
t=s[i]
n=s[len(s)-i-1]
s[i]=n
s[len(s)-i-1]=t
反转字符串中的单词
class Solution:
def reverseWords(self, s):
words=[]
for j in s.split(' '):
j = list(j)
for i in range(len(j) // 2):
t = j[i]
n = j[len(j) - i - 1]
j[i] = n
j[len(j) - i - 1] = t
words.append(''.join(j))
return ' '.join(i for i in words)