---
# System prepended metadata

title: \#344 Reverse String
tags: [leetcode, leetcode-easy]

---

# \#344 Reverse String
## *給定一字元array s, 回傳反轉後的string*
## Log
 - 20210626 修正:input s type為array, 如果是string要先轉為array才能用這個swap語法
 - build 20210626 by syhuang

## xxx
 - xxx
```javascript=
```
## 初見
 - swap頭尾兩元素直到陣列中央即完成反轉
```javascript=
var reverseString = function(s) {
    for(let i=0; i<s.length/2; i++){
        [s[i], s[s.length-i-1]] = [s[s.length-i-1], s[i]]
    }
};
```
## 備註
- javascript 字元編碼格式為UTF16
## 參考
- 對其他語言有ASCII或UNICODE等其他編碼格式分別的[參考解](https://leetcode.com/problems/reverse-string/discuss/80937/JAVA-Simple-and-Clean-with-Explanations-6-Solutions)
###### tags: `leetcode`, `leetcode-easy`