LeetCode345. Reverse Vowels of a String
345. Reverse Vowels of a String
My Submissions QuestionEditorial Solution
Total Accepted: 3821 Total Submissions: 10524 Difficulty: Easy
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”.
Subscribe to see which companies asked this question
class Solution {
public:string reverseVowels(string s) {int i = 0, j = s.length() - 1;while(i < j) {while(i < j && s[i] != 'a' && s[i] != 'e' && s[i] != 'i' && s[i] != 'o' && s[i] != 'u'&& s[i] != 'A' && s[i] != 'E' && s[i] != 'I' && s[i] != 'O' && s[i] != 'U') {i++;}while(i < j && s[j] != 'a' && s[j] != 'e' && s[j] != 'i' && s[j] != 'o' && s[j] != 'u'&& s[j] != 'A' && s[j] != 'E' && s[j] != 'I' && s[j] != 'O' && s[j] != 'U') {j--;}if(i < j) {swap(s[i], s[j]);}i++;j--;}return s;}
};
LeetCode345. Reverse Vowels of a String相关推荐
- leetcode345——Reverse Vowels of a String(C++)
Write a function that takes a string as input and reverse only the vowels of a string. Example 1: Gi ...
- Reverse Vowels of a String (反转字符串中的母音)
leetcode Reverse Vowels of a String 反转字符串中的母音 一.学习要点: 1.find_first_of:查找与字符串str中某个字符相同的位置,并返回他的第一个出现 ...
- 345. Reverse Vowels of a String - LeetCode
Question 345. Reverse Vowels of a String Solution 思路:交换元音,第一次遍历,先把出现元音的索引位置记录下来,第二遍遍历元音的索引并替换. Java实 ...
- 345.反转字符串中的元音字母(Reverse Vowels of a String)
题目描述 编写一个函数,以字符串作为输入,反转该字符串中的元音字母. 示例 1: 给定 s = "hello", 返回 "holle". 示例 2: 给定 s ...
- 从零开始的LC刷题(74): Reverse Vowels of a String
原题: Write a function that takes a string as input and reverse only the vowels of a string. Example 1 ...
- LeetCode:345. Reverse Vowels of a String
051103 题目 Write a function that takes a string as input and reverse only the vowels of a string. Exa ...
- Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string. Example 1: Gi ...
- LeetCode Reverse Vowels of a String
原题链接在这里:https://leetcode.com/problems/reverse-vowels-of-a-string/ 题目: Write a function that takes a ...
- LeetCode 345. Reverse Vowels of a String
题目: Write a function that takes a string as input and reverse only the vowels of a string. Example 1 ...
最新文章
- 昵称到拼音php,php 汉字转换拼音程序_PHP教程
- 三: cocos2d-x代码分析
- git 分支合并到当前
- php psr2规范,php标准规范详解
- zookeeper宏观认识
- 江苏省专转本计算机题知识点,江苏专转本计算机真题17
- 如何用java实现使用电子邮件控制你的电脑
- [UITableView]简介
- 三星s9 港版android 9.0,国行三星Galaxy S9/S9+更新One UI正式版,基于安卓9.0
- tcpClient的使用
- Unity编辑器扩展——撤回
- 【FCN】Fully Convolutional Networks for Semantic Segmentation学习
- 关于HDR的学习笔记
- 在ARM板上的linux系统中查看进程实际使用物理内存
- 2Opinion Word Expansion and Target Extraction through Double Propagation(2020-10-18)
- 计算机网络应用技术小结
- 基于Java的留言板系统的设计与实现
- 用eclipse配置hibernate的hbm.xml文件时遇到的一些问题
- JDK动态代理用例及源码解析
- 加载的图片太多或太大如何优化