[Leetcode] Reverse Vowels of a String
来源:互联网 发布:网页数据库查询系统 编辑:程序博客网 时间:2024/05/20 06:24
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".
Note:
The vowels does not include the letter "y".
public class Solution { public String reverseVowels(String s) { StringBuffer Vowels=new StringBuffer(); StringBuffer reversed=new StringBuffer(); int vowelsCount=0; for(int i=0;i<s.length();i++) { if(s.charAt(i)=='a'||s.charAt(i)=='e'||s.charAt(i)=='i'||s.charAt(i)=='o'||s.charAt(i)=='u'||s.charAt(i)=='A'||s.charAt(i)=='E'||s.charAt(i)=='I'||s.charAt(i)=='O'||s.charAt(i)=='U') { Vowels.append(s.charAt(i)); vowelsCount+=1; } } for(int i=0;i<s.length();i++) { if(s.charAt(i)=='a'||s.charAt(i)=='e'||s.charAt(i)=='i'||s.charAt(i)=='o'||s.charAt(i)=='u'||s.charAt(i)=='A'||s.charAt(i)=='E'||s.charAt(i)=='I'||s.charAt(i)=='O'||s.charAt(i)=='U') { reversed.append(Vowels.toString().charAt(vowelsCount-1)); vowelsCount-=1; } else reversed.append(s.charAt(i)); } return reversed.toString(); }}
0 0
- Leetcode Reverse Vowels of a String 345
- LeetCode 345. Reverse Vowels of a String
- LeetCode - Reverse Vowels of a String
- leetcode-345. Reverse Vowels of a String
- 【LeetCode-345】Reverse Vowels of a String
- #leetcode#345. Reverse Vowels of a String
- leetcode 345Reverse vowels of a string
- [leetcode] 345. Reverse Vowels of a String
- Leetcode:345. Reverse Vowels of a String
- LeetCode *** 345. Reverse Vowels of a String
- leetcode 345:Reverse Vowels of a String
- leetcode笔记:Reverse Vowels of a String
- LeetCode 345 Reverse Vowels of a String
- LeetCode:Reverse Vowels of a String
- LeetCode.345. Reverse Vowels of a String
- LeetCode 345 Reverse Vowels of a String
- Leetcode - Reverse Vowels of a String
- LeetCode 345. Reverse Vowels of a String
- java 函数定义格式
- 自定义View实现钟摆效果进度条PendulumView
- HDU 1212 Big Number
- 高并发
- 二叉搜索树
- [Leetcode] Reverse Vowels of a String
- Android 内存溢出和内存泄漏的区别
- 第四周项目1-建立单链表
- 欢迎使用CSDN-markdown编辑器
- Qt小传——从诞生到发展、繁荣
- Anaconda Note(辨公室)
- 逻辑地址、线性地址、物理地址和虚拟地址 概念与区别
- HDU 5867 Water problem
- ContentProvider 浅谈