[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 ...
随机推荐
- POJ 3321 Apple Tree 树状数组 第一题
第一次做树状数组,这个东西还是蛮神奇的,通过一个简单的C数组就可以表示出整个序列的值,并且可以用logN的复杂度进行改值与求和. 这道题目我根本不知道怎么和树状数组扯上的关系,刚开始我想直接按图来遍历 ...
- SEO初步学习之影响网站排名的因素
本文介绍一些比较明显的因素,一些隐藏较深的原因还有待发掘: 1.采集网站内容,即抄袭其他网站的内容. 2.新站上传后建议不要有大的改动. 3.标题频繁修改. 4.大量投放垃圾外链. 5.不做友链,交友 ...
- shell 实现war包的配置更新和自动发布
此脚本主要用来实现非maven tomcat项目的war包手动发布, 1.将测试war包上传至指定目录 2.备份目前生产代码 3.自动配置文件替换 4.新版本代码的发布 #!/bin/bash ### ...
- ADB 用法大全 【转】
https://github.com/mzlogin/awesome-adb awesome-adb ADB,即 Android Debug Bridge,它是 Android 开发/测试人员不可替代 ...
- sudo apt-get update数字签名错误解决方法
lzb@lzb:~/projects/curl-master$ sudo apt-get update 命中: http://mirrors.aliyun.com/ubuntu xenial InRe ...
- 函数返回值return
#函数后面如果没有return系统会默认return none def ff(): print("打印return") return 15 # 函数在执行中遇到return就会停止 ...
- C语言 指针理解
1.指针 指针全称是指针变量,其实质是C语言的一种变量.这种变量比较特殊,通常他的值会被赋值为某个变量的地址值(p = &a),然后我们可以使用 *p 这样的方式去间接访问p所指向的那个变量. ...
- 拾起HTML+CSS的一天
今天在w3school看了下HTML5和CSS3的新特性. 本来觉得自己对CSS方面基础还挺有把握的,就之前自学都是跳过这个模块的,但经过昨天会友的面试,感觉自己好像太忽视基础了,很多基本的东西很模糊 ...
- CodeForces 438D The Child and Sequence (线段树 暴力)
传送门 题目大意: 给你一个序列,要求在序列上维护三个操作: 1)区间求和 2)区间取模 3)单点修改 这里的操作二很讨厌,取模必须模到叶子节点上,否则跑出来肯定是错的.没有操作二就是线段树水题了. ...
- mplayer 的安装步骤
编译mplayer: make distclean ./configure --disable-png --disable-gif //加后面的是因为编译时出错了,也可以直接 ./con ...