Leetcode:345. Reverse Vowels of a String
来源:互联网 发布:win7系统优化批处理 编辑:程序博客网 时间:2024/04/29 13:14
题目描述:
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”.
此题很简单,就是把字符串中的元音字母反转,但是本宝宝却把它做复杂了。大神勿喷,后面有时间会改进的。
import java.util.HashMap;import java.util.Iterator;import java.util.LinkedHashMap;public class Solution { public String reverseVowels(String s) { char[] a=s.toCharArray(); HashMap<Integer,String> hashMap = new LinkedHashMap<Integer, String>(); char[] temp=new char[a.length]; int k=0; for(int i=0;i<a.length;i++){ if((a[i]=='a')||(a[i]=='A')||(a[i]=='E')||(a[i]=='I')||(a[i]=='O')||(a[i]=='U')||(a[i]=='e')||(a[i]=='i')||(a[i]=='o')||(a[i]=='u')){ hashMap.put(i,String.valueOf(a[i])); temp[k]=a[i]; k++; } } char[] bb=new char[hashMap.size()]; int j=0; for(int i=hashMap.size()-1;i>=0;i--){ bb[j]=temp[i]; j++; } int kk=0; Iterator iterator=hashMap.keySet().iterator(); while(iterator.hasNext()){ Integer key=(Integer) iterator.next(); a[key]=bb[kk]; kk++; } return String.valueOf(a); }}
0 0
- 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: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 345. Reverse Vowels of a String
- LeetCode 345. Reverse Vowels of a String
- 345.[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】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
- AOP的两种实现方式
- 【linq to sql】步骤
- 写Appcan iOS插件,遇到个问题,修改c文件运行不变化,被91(百度手机)助手坑了。
- 安装mysql Install/Remove of the Service Denied!错误的解决办法
- svn通过hook开启修改提交日志权限pre-revprop-change
- Leetcode:345. Reverse Vowels of a String
- 最实用的代码重构小技巧排行榜TOP10
- [Unity热更新]tolua# & LuaFramework(九):网络通信实例
- 场效应晶体管使用详解
- sql语句中函数
- iOS开发--多线程编程(一)NSThread
- struts2启动报错com/opensymphony/xwork2/spring/SpringObjectFactory.java:220:-1
- Redis与Memcached的区别
- iOS开发网络篇—发送GET和POST请求(使用NSURLSession)