写出一个程序,接受一个字符串,然后输出该字符串反转后的字符串。(字符串长度不超过1000)
数据范围:
要求:空间复杂度 ,时间复杂度
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # 反转字符串 # @param str string字符串 # @return string字符串 # class Solution: def solve(self , str: str) -> str: # write code here a=[] b="" for i in str: a.append(i) while a: b=b+a.pop() return b
def solve(self , str: str) -> str: # write code here res = '' for i in str: res = i + res return res
class Solution: def solve(self , str: str) -> str: return str[::-1]
class Solution: def solve(self , str: str) -> str: # write code here test_list = [] for i in str: test_list.append(i) test_list.reverse() r = "".join(test_list) return r