[LC] 345. Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string.
Example 1:
Input: "hello"
Output: "holle"
Example 2:
Input: "leetcode"
Output: "leotcede"
class Solution {
public String reverseVowels(String s) {
if (s == null || s.length() == 0) {
return s;
}
char[] charArr = s.toCharArray();
int start = 0, end = charArr.length - 1;
while (start < end) {
if (!isVowel(charArr[start])) {
start += 1;
} else if (!isVowel(charArr[end])) {
end -= 1;
} else {
char tmp = charArr[start];
charArr[start] = charArr[end];
charArr[end] = tmp;
start += 1;
end -= 1;
}
}
return new String(charArr);
} private boolean isVowel(Character c) {
return c == 'a' || c == 'A' || c == 'e' || c == 'E' || c == 'i' || c == 'I' || c == 'o' || c == 'O' || c == 'u' || c == 'U';
}
}
[LC] 345. Reverse Vowels of a String的更多相关文章
- 345. Reverse Vowels of a String(C++)
345. Reverse Vowels of a String Write a function that takes a string as input and reverse only the v ...
- 【leetcode】345. Reverse Vowels of a String
problem 345. Reverse Vowels of a String class Solution { public: string reverseVowels(string s) { , ...
- 345. Reverse Vowels of a String【easy】
345. Reverse Vowels of a String[easy] Write a function that takes a string as input and reverse only ...
- 345. Reverse Vowels of a String - LeetCode
Question 345. Reverse Vowels of a String Solution 思路:交换元音,第一次遍历,先把出现元音的索引位置记录下来,第二遍遍历元音的索引并替换. Java实 ...
- 345. Reverse Vowels of a String翻转字符串中的元音字母
[抄题]: Write a function that takes a string as input and reverse only the vowels of a string. Example ...
- 345. Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string. Example 1:Giv ...
- Python [Leetcode 345]Reverse Vowels of a String
题目描述: Write a function that takes a string as input and reverse only the vowels of a string. Example ...
- 【一天一道LeetCode】#345. Reverse Vowels of a String
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Write a ...
- 345. Reverse Vowels of a String【Easy】【双指针-反转字符串中的元音字符】
Write a function that takes a string as input and reverse only the vowels of a string. Example 1: In ...
随机推荐
- winform显示、隐藏任务栏及开始菜单
private const int SW_HIDE = 0; //隐藏 private const int SW_RESTORE = 9;//显示 /// <summary> /// 获取 ...
- VUE- 访问服务器端数据 Vue-resource
VUE- 访问服务器端数据 Vue-resource 1. 安装 vue-resource cnpm install vue-resource --save 安装完毕后,在main.js中导入,如下所 ...
- SQLServer多条件查询技巧
2019-10-15 13:31:04 在实际项目开发中,有很多页面都会出现多条件查询功能,类似于这种情况: 牵扯到数据就少不了数据库了.这么多条件的查询,如果要用常规的if else来写判断逻辑的 ...
- PAT B1045 快速排序
题目如下: 1045 快速排序 (25 point(s)) 著名的快速排序算法里有一个经典的划分过程:我们通常采用某种方法取一个元素作为主元,通过交换,把比主元小的元素放到它的左边,比主元大的元素放到 ...
- Idea Spring工程不识别注解
如图所示 Idea工具报出很多注解不识别,开始怀疑是 工具问题,重装Idea.配置lombak都不行,切换分支发现正常,一定是合入代码修改啥了,一行行比对,果然是这行 import org.sprin ...
- vim 马哥
VIM编辑器 编辑模式 默认 输入模式 i 末行模式 : vim +# file #打开文件后直接跳到第#行 vim + file 直接跳到尾行 vim +/关键字 跳转到 ...
- Python说文解字_杂谈01
1. Python在Ubuntu下面下载Python 2. 安装依赖包 sudo apt-get update sudo apt-get install build-essential python- ...
- goahead调试经验
一.参考网址 1.源码的github地址 2.Web开发之Goahead 二.技术细节 1.默认网页的存放目录和名称 1)目录:在main.c文件中有*rootWeb定义,如: 2)网页名:在mai ...
- dfs--迷宫
题目背景 给定一个N*M方格的迷宫,迷宫里有T处障碍,障碍处不可通过.给定起点坐标和终点坐标,问: 每个方格最多经过1次,有多少种从起点坐标到终点坐标的方案.在迷宫中移动有上下左右四种方式,每次只能移 ...
- Linux(CENTOS7) Mysql不能远程连接解决办法
今天,在腾讯云的服务器上面装了一个Mysql,装完发现我在linux下面可以连接,但是在我的window下面是用mysql可视化工具(SQLyog)连接不了,错误如下: Host ‘’ is not ...