We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
编写一个函数,以字符串作为输入,反转该字符串中的元音字母。
示例 1:
输入: "hello" 输出: "holle"
示例 2:
输入: "leetcode" 输出: "leotcede"
说明: 元音字母不包含字母"y"。
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/reverse-vowels-of-a-string 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
解法: 1一个从头部开始 一个从尾部开始查找元音字母; 2 找到以后 元素 交换 3 在头尾交互点结束。
/** * @param {string} s * @return {string} */ var reverseVowels = function(s) { let arr = s.split(''); let i = 0, j = arr.length - 1; let reg=/[aeiou]$/i; while (i < j) { if (reg.test(arr[i]) && reg.test(arr[j])) { [arr[i], arr[j]] = [arr[j], arr[i]]; //es6 交换 i++; j--; }else if (reg.test(arr[i])){ j--;} else{i++;} } return arr.join(''); };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
编写一个函数,以字符串作为输入,反转该字符串中的元音字母。
示例 1:
示例 2:
说明:
元音字母不包含字母"y"。
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/reverse-vowels-of-a-string
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
解法:
1一个从头部开始 一个从尾部开始查找元音字母;
2 找到以后 元素 交换
3 在头尾交互点结束。
The text was updated successfully, but these errors were encountered: