leetcode -- 345. Reverse Vowels of a String 【双指针 + 逆序的变形】
来源:互联网 发布:周扬青 淘宝 编辑:程序博客网 时间:2024/06/05 17:00
题目
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".
题意
给定一个字符串,只将字符串的原因进行逆序。
分析及解答
- 双指针 (high ,low)
- 参照物:
String vowels = "aeiouAEIOU";
public class Solution {public String reverseVowels(String s) { char[] array = s.toCharArray(); int low = 0,high = array.length -1; boolean isLowVow = false, isHighVow = false; String vowels = "aeiouAEIOU"; //逆序的核心代码 while(low < high){ isLowVow = (vowels.indexOf(array[low]) != -1); isHighVow = (vowels.indexOf(array[high]) != -1); if(isHighVow && isLowVow){ char tmp = array[low]; array[low] = array[high]; array[high] = tmp; low++; high--; }else{ if(!isLowVow){ low++; } if(!isHighVow){ high--; } } } return String.valueOf(array); }}
阅读全文
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
- 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
- 多行数据输出与处理
- 2016 Pacific Northwest Region Programming Contest—Division 2 Problem R — limit 1 second Equality
- Intel P6以来核心架构及对应型号、芯片组一览表
- Fragment replace的使用
- 【UOJ261 BZOJ 】天天爱跑步(线段树合并)
- leetcode -- 345. Reverse Vowels of a String 【双指针 + 逆序的变形】
- Mybatis:ReflectionException: There is no getter for property named 'productName' in 'class java.lang
- 搜索 棋盘问题
- 内存的几个小问题
- codeforces 821d Okabe and City
- 安装Python3-ipython
- NKOJ 3252 (CQOI 2015) 多项式(数学,高精度)
- 暑期集训之最大公约数问题
- jdbc 工具类的抽取