Reverse Vowels of a String
https://www.lintcode.com/problem/reverse-vowels-of-a-string/description
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;
public class Solution {
/**
* @param s: a string
* @return: reverse only the vowels of a string
*/
public String reverseVowels(String s) {
// write your code here
LinkedList<Integer> list = new LinkedList<>();
char[] chars = s.toCharArray();
Set<Character> set = new HashSet<>();
set.add('a');
set.add('e');
set.add('i');
set.add('o');
set.add('u');
for (int i = 0; i < chars.length; i++) {
char aChar = chars[i];
if (set.contains(Character.toLowerCase(aChar))) {
list.add(i);
}
}
while (list.size() > 1) {
int left = list.removeFirst();
int right = list.removeLast();
char aChar = chars[left];
chars[left] = chars[right];
chars[right] = aChar;
}
return new String(chars);
}
}
相關文章
- leetcode 344. Reverse StringLeetCode
- Leetcode 151 Reverse Words in a StringLeetCode
- Reverse a String-freecodecamp演算法題目演算法
- vowels.c
- 017 Vowels match
- JavaScript reverse()JavaScript
- BUUCTF reverse 3
- 1074 reverse list
- 23.【Reverse】
- Hgame2023 ReverseGAM
- Reverse 攻防世界合集
- Reverse Card (Hard Version)
- hackme 【攻防世界】Reverse
- Leetcode 7 Reverse IntegerLeetCode
- Reverse學習筆記筆記
- Leetcode 206. Reverse Linked ListLeetCode
- 92. Reverse Linked List II
- 精讀《ObjectEntries, Shift, Reverse...》Object
- UNCTF2021-reverse-部分wpTF2
- XCTF-Reverse:open-source
- [20210908]Reverse Shell with Bash.txt
- 4. render, redirect, HttpResponse, reverseHTTP
- String,String Builder,String Buffer-原始碼UI原始碼
- Failed to execute user defined function(anonfun$concatStr$1: (map<string,string>, string) => string)AIFunction
- python-reverse順序反轉Python
- for 迴圈中倒序 用reverse
- D2. Reverse Card (Hard Version)
- 攻防世界 Replace Reverse二星題
- LeetCode Reverse Integer(007)解法總結LeetCode
- 2021強網杯Reverse-LongTimeAgoGo
- LeetCode - Easy - 206. Reverse Linked ListLeetCode
- Leetcode 25 Reverse Nodes in k-GroupLeetCode
- CF1458D Flip and Reverse 題解
- How do I reverse selected lines order in Vim?
- [20230314]nc reverse bash shell alias.txt
- [20230310]nc reverse bash shell問題.txt
- CF1234F Yet Another Substring Reverse
- LeetCode - 解題筆記 - 7 - Reverse IntegerLeetCode筆記