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相关推荐

  1. 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 ...

  2. Reverse Vowels of a String (反转字符串中的母音)

    leetcode Reverse Vowels of a String 反转字符串中的母音 一.学习要点: 1.find_first_of:查找与字符串str中某个字符相同的位置,并返回他的第一个出现 ...

  3. 345. Reverse Vowels of a String - LeetCode

    Question 345. Reverse Vowels of a String Solution 思路:交换元音,第一次遍历,先把出现元音的索引位置记录下来,第二遍遍历元音的索引并替换. Java实 ...

  4. 345.反转字符串中的元音字母(Reverse Vowels of a String)

    题目描述 编写一个函数,以字符串作为输入,反转该字符串中的元音字母. 示例 1: 给定 s = "hello", 返回 "holle". 示例 2: 给定 s ...

  5. 从零开始的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 ...

  6. 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 ...

  7. 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 ...

  8. LeetCode Reverse Vowels of a String

    原题链接在这里:https://leetcode.com/problems/reverse-vowels-of-a-string/ 题目: Write a function that takes a ...

  9. 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 ...

最新文章

  1. 昵称到拼音php,php 汉字转换拼音程序_PHP教程
  2. 三: cocos2d-x代码分析
  3. git 分支合并到当前
  4. php psr2规范,php标准规范详解
  5. zookeeper宏观认识
  6. 江苏省专转本计算机题知识点,江苏专转本计算机真题17
  7. 如何用java实现使用电子邮件控制你的电脑
  8. [UITableView]简介
  9. 三星s9 港版android 9.0,国行三星Galaxy S9/S9+更新One UI正式版,基于安卓9.0
  10. tcpClient的使用
  11. Unity编辑器扩展——撤回
  12. 【FCN】Fully Convolutional Networks for Semantic Segmentation学习
  13. 关于HDR的学习笔记
  14. 在ARM板上的linux系统中查看进程实际使用物理内存
  15. 2Opinion Word Expansion and Target Extraction through Double Propagation(2020-10-18)
  16. 计算机网络应用技术小结
  17. 基于Java的留言板系统的设计与实现
  18. 用eclipse配置hibernate的hbm.xml文件时遇到的一些问题
  19. JDK动态代理用例及源码解析
  20. 加载的图片太多或太大如何优化

热门文章

  1. Java中SimpleDateFormat用法详解
  2. javascript错误处理与调试(转)
  3. 安全小测试:介绍一个简单web安全知识测试的网站
  4. 那一天,那一月,那一年,那一世,那一瞬
  5. android中MVC,MVP和MVVM三种模式详解析
  6. Drawing with GoogLeNet
  7. poj 3335 Rotating Scoreboard - 半平面交
  8. Obez'yanka-Nol
  9. sublime theme color
  10. Hacker Plus:Facebook 推出漏洞奖励 “忠诚计划”