LeetCode No.345 Reverse Vowels of a String
来源:互联网 发布:tftp 使用端口 编辑:程序博客网 时间:2024/06/03 23:47
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".
====================================================================================
题目链接:https://leetcode.com/problems/reverse-vowels-of-a-string/
题目大意:颠倒字符串中的元音。
思路:记录元音下标,交换前后下标字符。
参考代码:
class Solution {public: string reverseVowels(string s) { vector <int> index ; int n = s.size() ; for ( int i = 0 ; i < n ; i ++ ) if ( isVowel ( s[i] ) ) index.push_back ( i ) ; int m = index.size() ; for ( int i = 0 ; i < m / 2 ; i ++ ) { char ch = s[index[i]] ; s[index[i]] = s[index[m-i-1]] ; s[index[m-i-1]] = ch ; } return s ; }private : bool isVowel ( char ch ) { return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U'; } };
0 0
- LeetCode--No.345--Reverse Vowels of a String
- LeetCode No.345 Reverse Vowels of a String
- Leetcode Reverse Vowels of a String 345
- 【LeetCode-345】Reverse Vowels of a String
- leetcode 345Reverse vowels of a string
- leetcode 345:Reverse Vowels of a String
- LeetCode 345 Reverse Vowels of a String
- LeetCode 345 Reverse Vowels of a String
- LeetCode 345:Reverse Vowels of a String
- LeetCode 345: Reverse Vowels of a String
- leetcode 345 Reverse Vowels of a String
- leetcode 345 Reverse Vowels of a String
- LeetCode[345] Reverse Vowels of a String
- Leetcode-345-Reverse Vowels of a String
- LeetCode 345 Reverse Vowels of a String
- leetcode 345 Reverse Vowels of a String
- LeetCode 345 Reverse Vowels of a String
- LeetCode.345 Reverse Vowels of a String
- poj1276 Cash Machine(多重背包)
- MSP430FRx 微控制器:收集更多数据,作出更明智的决策
- Markdown使用说明
- respond.js 解决IE6~8的响应式布局问题
- 树莓派3下PDO访问MSSQL
- LeetCode No.345 Reverse Vowels of a String
- 同步工具类之——Latch
- pycharm 使用心得(七)一些实用功能介绍
- TI全新汽车霍尔传感器: 精准定位、轻松感应
- javaES6箭头函数的全新特性
- struts2怎么使用redis共享
- eclipse搭建maven web 工程,和集成springmvc+mybatis的一些问题
- C#第一章 上机习题3
- 什么是接口服务器