• #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;
        }
    };
    

      

  • 相关阅读:
    Redis(二)
    Redis(一)
    MyBatis--一级二级缓存
    MySQL优化
    HashMap
    ArrayList
    常用框架注解说明
    Linux常用基础命令
    SpringCloud--gateway路由配置
    JetBrains系列软件的插件安装
  • 原文地址:https://www.cnblogs.com/xiaohaigege/p/5463432.html
Copyright © 2020-2023  润新知