zoukankan      html  css  js  c++  java
  • 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".

     1 char* reverseVowels(char* s) {
     2     int i;
     3     int j;
     4     char temp;
     5     i = 0;
     6     j = strlen(s) - 1;
     7     while(i < j){
     8     
     9         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')
    10             i++;
    11         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')
    12             j--;
    13         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') && (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'))
    14         {
    15             temp = s[i];
    16             s[i] = s[j];
    17             s[j] = temp;
    18             i++;
    19             j--;
    20         }
    21             
    22     }
    23     return s;
    24 }
  • 相关阅读:
    三角形的个数
    Nightmare(搜索)
    Prime Ring Problem(搜索)
    Safecracker(搜索)
    丑数
    八皇后问题(回溯法)
    Dijkstra
    floyd详解
    继续畅通工程(kruskal prim)
    畅通工程
  • 原文地址:https://www.cnblogs.com/boluo007/p/5479683.html
Copyright © 2011-2022 走看看