首页 > 学院 > 开发设计 > 正文

LEETCODE--Reverse Vowels of a String

2019-11-08 02:03:52
字体:
来源:转载
供稿:网友

Write a function that takes a string as input and reverse only the vowels of a string. Example 1: Given s = “hello”, return “holle”. Example 2: Given s = “leetcode”, return “leotcede”. Note: The vowels does not include the letter “y”.

class Solution {public: string reverseVowels(string s) { int left = 0; int right = s.length() - 1; while(left < right ){ while(left < right && s[left] != 'a' && s[left] != 'e' && s[left] != 'i' && s[left] != 'o' && s[left] != 'u' && s[left] != 'A' && s[left] != 'E' && s[left] != 'I' && s[left] != 'O' && s[left] != 'U' ){ left++; } while(left < right && s[right] != 'a' && s[right] != 'e' && s[right] != 'i' && s[right] != 'o' && s[right] != 'u' && s[right] != 'A' && s[right] != 'E' && s[right] != 'I' && s[right] != 'O' && s[right] != 'U' ){ right--; } char c = s[right]; s[right--] = s[left]; s[left++] = c; } return s; }};
上一篇:正则表达式

下一篇:$_SERVER各种用法

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表