zoukankan      html  css  js  c++  java
  • 345. Reverse Vowels of a String Java Solutions

    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

     
     
     1 public class Solution {
     2     public String reverseVowels(String s) {
     3         if(null == s) return s;
     4         char[] tmp = s.toCharArray();
     5         Stack<Character> stack = new Stack<Character>();
     6         for(int i = 0; i<tmp.length; i++){
     7             if(isVowels(tmp[i])){
     8                      stack.push(tmp[i]);
     9                 }
    10         }
    11         for(int i = 0; i<tmp.length; i++){
    12             if(isVowels(tmp[i])){
    13                     tmp[i] = stack.pop();
    14                 }
    15         }
    16         String res = new String(tmp);
    17         return res;
    18     }
    19     
    20     public boolean isVowels(char c){
    21         if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U' ){
    22                     return true;
    23         }
    24         return false;
    25     }
  • 相关阅读:
    nuxt.js 学习与记录
    图片上传预览 接收
    k8s之deployment
    k8s之service
    k8s的一些命令
    ansible 学习
    k8s之ConfigMap && secret
    k8s 之Job/CronJob
    k8s之PV & PVC
    配置ssh免密登录
  • 原文地址:https://www.cnblogs.com/guoguolan/p/5450694.html
Copyright © 2011-2022 走看看