/
githubmirror
/
interviews
Обзор
Документация
Войти
/
githubmirror
/
interviews
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
leetcode/string/ReverseVowelsOfAString.java
44 строки
1 KB
Kevin Naughton Jr
finish renaming files and directories
27 мар 2018, 19:52
27 мар 2018, 19:52
ec6dfb5
Код
Авторство
О чём код?
// 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 ReverseVowelsOfAString { public String reverseVowels(String s) { if(s == null || s.length() == 0) { return s; } String vowels = "aeiouAEIOU"; char[] chars = s.toCharArray(); int start = 0; int end = s.length() - 1; while(start < end) { while(start < end && !vowels.contains(chars[start] + "")) { start++; } while(start < end && !vowels.contains(chars[end] + "")) { end--; } char temp = chars[start]; chars[start] = chars[end]; chars[end] = temp; start++; end--; } return new String(chars); } }