# \#345 Reverse Vowels of a String
## *給定字串s, 反轉s中的"母音"字元(即a,e,i,o,u,不管case)*
## Log
- build 20210626 by syhuang
## 初見
- 類似#344, 從字串頭尾開始判斷每個字元是否為指定字元
```javascript=
var reverseVowels = function(s) {
let t = s.split('');
const map = new Map([['a',1],['e',1],['i',1],['o',1],['u',1],
['A',1],['E',1],['I',1],['O',1],['U',1]]);
let left = 0, right = s.length-1;
let matchLeft = false, matchRight = false;
while(left < right){
if(!map.has(t[left])) left++;
else matchLeft = true;
if(!map.has(t[right])) right--;
else matchRight = true;
if(matchLeft && matchRight){
[t[left],t[right]] = [t[right],t[left]];
left++,right--;
matchLeft = matchRight = false;
}
}
return t.join('');
};
```
## 備註
## 參考
###### tags: `leetcode`, `leetcode-easy`