Easy-题目71：345. Reverse Vowels of a String（增补4）

Write a function that takes a string as input and reverse only the vowels of a string.

public String reverseVowels(String s) {
Set<Character> vowels = new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u'));
char[] chars = s.toCharArray();
int l = 0, r = chars.length-1;
while (l < r) {
while (l < r && !vowels.contains(Character.toLowerCase(chars[l]))) {
l++;
}
while (l < r && !vowels.contains(Character.toLowerCase(chars[r]))) {
r--;
}
char tmp = chars[l];
chars[l++] = chars[r];
chars[r--] = tmp;
}
return new String(chars);
}

17ms

leetcode_345 Reverse Vowels of a String

2016-05-12 21:04:34

【LeetCode】345 Reverse Vowels of a String（java）

2016-05-04 16:15:30

LeetCode345—Reverse Vowels of a String

2016-04-28 15:39:00

345. Reverse Vowels of a String [easy] (Python)

2016-06-01 14:10:20

Reverse Vowels of a String

2016年04月29日 684B 下载

345. Reverse Vowels of a String

2016-04-24 14:58:52

345. Reverse Vowels of a String*

2016-08-08 15:34:29

345. Reverse Vowels of a String

2018-05-04 21:33:24

String:345. Reverse Vowels of a String

2017-09-11 16:26:47

345.[LeetCode]Reverse Vowels of a String

2016-05-13 00:44:14