[LeetCode] 344. Reverse String
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
Given s = "hello", return "olleh".
Subscribe to see which companies asked this question
這題需要考量空間 跟 時間的使用
所以 不能多申請一個 string, 也不能跑好幾個 loop
思路:
1. python 的 string 不能更改element, 所以先改成 list
2. 用兩個pointer 分別指到 頭跟尾
3. 用一個for loop 掃 len(s)/2 次
留言
張貼留言