题解 | #反转字符串#
反转字符串
http://www.nowcoder.com/practice/c3a6afee325e472386a1c4eb1ef987f3
#
# 反转字符串
# @param str string字符串
# @return string字符串
#
def swap(str1,i,j):
t = str1[i]
str1[i] = str1[j]
str1[j] = t
class Solution:
def solve(self , str1):
# write code here
if str1 is None or str1 == "": return str1
str2 = list(str1)
i,j = 0,len(str2)-1
while i<j:
swap(str2, i, j)
i+=1;j-=1
return ''.join(str2) 