zoukankan      html  css  js  c++  java
  • #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:
    Given s = "hello", return "holle".

    Example 2:
    Given s = "leetcode", return "leotcede".

    题意:将一个字符串中a,e,i,o,u收尾互换位置,返回。

    class Solution {
    public:
        string reverseVowels(string s) {
            int len = s.length();
            char temp;
            for(int i = 0, j = len - 1; i < j; i++) {
                if(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') { 
                	for(j; j > i; j--)
                	if(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') {
    					temp = s[i];
    					s[i] = s[j];
    					s[j] = temp;
    					j--;
    					break;
    				}
    			} 
    		} 
            return s;
        }
    };
    

      

  • 相关阅读:
    二 Capacity Scheduler 计算能力调度器
    一:yarn 介绍
    2.hbase原理(未完待续)
    1.安装hbase
    创建第一个vue项目
    初学vue(二)
    第一次面试
    面试题
    C#冒泡排序
    面试真题(.NET/Sqlserver/web前端)
  • 原文地址:https://www.cnblogs.com/xiaohaigege/p/5463432.html
Copyright © 2011-2022 走看看