Reverse Vowels of a String
来源:互联网 发布:阿里云服务器无法连接 编辑:程序博客网 时间:2024/06/09 02:10
一、问题描述
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".
二、思路
类似题目:Reverse String
三、代码
class Solution {public: bool isVowels(char t){ if(t == 'a'|| t == 'o' || t =='e' || t == 'i' || t == 'u'||t == 'A'|| t == 'O' || t =='E' || t == 'I' || t == 'U') return true; return false; } string reverseVowels(string s) { if(s == "") return ""; for(int i = 0,j = s.size() - 1; i < j;){ while(isVowels(s[i]) == false && i < j) ++i; while(isVowels(s[j]) == false && i < j) --j; if(isVowels(s[i]) && isVowels(s[j])){ char c = s[i]; s[i] = s[j]; s[j] = c; ++i; --j; } } return s; }};
0 0
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- Reverse Vowels of a String
- String:345. Reverse Vowels of a String
- 345. Reverse Vowels of a String 【E】
- Leetcode Reverse Vowels of a String 345
- LeetCode 345. Reverse Vowels of a String
- 116.Reverse Vowels of a String
- python 版本控制及django,git的使用
- mysql 主从 配置
- HDU3001 Travelling(DP)
- JQ+MYSQL实现省市区联动JQ部分
- [LeetCode] 7. Reverse Integer
- Reverse Vowels of a String
- VF01生成billing凭证:BAPI_BILLINGDOC_CREATEMULTIPLE
- Xcode 8 的新功能一览
- Nginx简单部署实现反向代理的功能,附带资源包
- Java 遍历Map的方法
- CodeChef 2016年7月问题
- 进程的虚拟地址划分
- sea.js
- PMOS和NMOS在开关应用中高侧和低侧驱动的对比