將一個字串反轉後回傳。
範例: s= "hello", return "olleh"
def reverseString(instr):
lst = []
lst.extend(instr)
instrlen=len(instr)
for i in range(instrlen//2):
lst[i],lst[instrlen-i-1]=lst[instrlen-i-1],lst[i]
temp2=''.join(lst)
return temp2
print(reverseString("hello"))
TIPS
字串合併使用. ''.join(lst)
SWAP a 和 b 變數值
a,b=b,a
https://skyyen999.gitbooks.io/-leetcode-with-javascript/content/questions/13md.html