345. Reverse Vowels of a String
来源:互联网 发布:淘宝店pc端怎么装修 编辑:程序博客网 时间:2024/05/17 03:54
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 { static final String vowels = "aeiouAEIOU"; public String reverseVowels(String s) { int first = 0, last = s.length() - 1; char[] array = s.toCharArray(); while(first < last){ while(first < last && vowels.indexOf(array[first]) == -1){ first++; } while(first < last && vowels.indexOf(array[last]) == -1){ last--; } char temp = array[first]; array[first] = array[last]; array[last] = temp; first++; last--; } return new String(array); } }
阅读全文
0 0
- String:345. Reverse Vowels of a String
- 345. Reverse Vowels of a String 【E】
- LeetCode 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- leetcode-345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- #leetcode#345. Reverse Vowels of a String
- [leetcode] 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- Leetcode:345. Reverse Vowels of a String
- LeetCode *** 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- LeetCode.345. Reverse Vowels of a String
- 345. Reverse Vowels of a String
- LeetCode 345. Reverse Vowels of a String
- day_14 C语言字符串处理和清空缓冲区
- JavaScript 创建对象的七种方式
- MySQL字符型数字比较大小
- bLue的苹果--有点坑
- 《机器学习实战》学习笔记-第三章-决策树
- 345. Reverse Vowels of a String
- 实例1.1 最大子列和问题
- 【codeforces】A. Array(思维水题)
- QT在VS环境下双击*.ui打不开Qt designer(Qt设计师)的解决方法
- undefined reference to `vtable for __cxxabiv1:
- mybatis关系映射之一对多和多对一
- Tomcat上进行项目部署与WAR包含义
- JMS学习一(JMS介绍)
- VBA中的数据字典,可以理解为Java中的Map