345. Reverse Vowels of a String
来源:互联网 发布:淘宝打折第二件原价 编辑:程序博客网 时间:2024/05/29 19:02
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”.
题目就是只翻转字符串中的元音字母,很简单。
class Solution {public: bool judge(char t){ char v[11]={'a','e','i','o','u','A','E','I','O','U'}; for(int i=0;i<10;i++){ if(t==v[i]) return true; } return false; } string reverseVowels(string s) { int len=s.size(); int i=0,j=len-1; while(i<j){ while(i<j&&judge(s[i])==false)i++; while(i<j&&judge(s[j])==false)j--; swap(s[i++],s[j--]);//这里记得要i++,j--; } return s; }};
0 0
- String:345. Reverse Vowels of a String
- 345. Reverse Vowels of a String 【E】
- LeetCode 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- leetcode-345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- #leetcode#345. Reverse Vowels of a String
- [leetcode] 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- Leetcode:345. Reverse Vowels of a String
- LeetCode *** 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- LeetCode.345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- LeetCode 345. Reverse Vowels of a String
- iOS 自定义UIPickerView地区选择器视图 —— HERO博客
- Python-Scrapy 个人兴趣教程(三):扫尾
- java.lang.UnsupportedClassVersionError问题的解决方法
- cmake中使用c++11
- ibatis去除无用where条件
- 345. Reverse Vowels of a String
- HttpClient PostAsync
- js 生成一维码(条形码)
- 【Android】线性布局和相对布局的比较
- Android中连续按两次返回键退出应用
- Java的线程
- The Steps of Machine Learning with Python
- QTcpSocket 及 TCP粘包分析
- c++ lambda闭包——c++复习(五)