题解 | #反转字符串#
反转字符串
https://www.nowcoder.com/practice/c3a6afee325e472386a1c4eb1ef987f3?tpId=295&tqId=1024337&ru=/exam/oj&qru=/ta/format-top101/question-ranking&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3D%25E7%25AE%2597%25E6%25B3%2595%25E7%25AF%2587%26topicId%3D295
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # 反转字符串 # @param str string字符串 # @return string字符串 #双指针,首个元素用i指引,尾部元素用j指引,不停的交换i和j的值,并累加+1 和减1直到i和j相遇 class Solution: def solve(self , str: str) -> str: # write code here L = list(str) i = 0 j = len(str)-1 while i<j: L[i],L[j]=L[j],L[i] i+=1 j-=1 return "".join(L)