当前位置:网站首页>Leetcode- reverse vowels in string - simple
Leetcode- reverse vowels in string - simple
2022-06-13 05:47:00 【AnWenRen】
title :345 Reverse vowels in a string - Simple
subject
Give you a string
s
, Invert only all vowels in the string , And return the result string .Vowels include
'a'
、'e'
、'i'
、'o'
、'u'
, And may appear in both case .
Example 1
Input :s = "hello"
Output :"holle"
Example 2
Input :s = "leetcode"
Output :"leotcede"
Tips
1 <= s.length <= 3 * 105
s
from Printable ASCII Character composition
Code Java
public String reverseVowels(String s) {
int start = 0;
int end = s.length()-1;
char[] str = s.toCharArray();
while (start < end) {
while(start < str.length){
char x = str[start];
if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u'
|| x == 'A' || x == 'E' || x == 'I' || x == 'O' || x == 'U') {
break;
}
start ++;
}
while(end >= 0){
char x = str[end];
if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u'
|| x == 'A' || x == 'E' || x == 'I' || x == 'O' || x == 'U') {
break;
}
end --;
}
if (start < end){
char temp = str[start];
str[start] = str[end];
str[end] = temp;
start ++;
end --;
} else break;
}
return new String(str);
}
边栏推荐
- MySQL main query and sub query
- Standard input dialog for pyqt5 qinputdialog
- Tongweb crawl performance log script
- 13 cancelendevent of a flowable end event and compensationthrowing of a compensation event
- Service architecture diagram of Nacos series
- Tongweb card, tongweb card, tongweb card
- Input a number and output each digit from high to low
- ZABBIX proxy, sender (without agent monitoring), performance optimization
- Feel the power of shardingsphere JDBC through the demo
- 零拷贝技术
猜你喜欢
Solutions to conflicts between xampp and VMware port 443
How to Algorithm Evaluation Methods
How to Algorithm Evaluation Methods
MySQL performs an inner join on query. The query result is incorrect because the associated fields have different field types.
3. Postman easy to use
Sentinel series hot spot current limiting
ZABBIX wechat alarm
12 error end event and terminateendevent of end event
19 calling subprocess (callactivity) of a flowable task
A simple recursion problem of linked list
随机推荐
Information collection for network security (2)
Nacos series registry principle and source code analysis
MySQL table data modification
redis
零拷贝技术
Compilation croisée helloworld avec cmake
@Detailed explanation of propertysource usage method and operation principle mechanism
Tongweb card, tongweb card, tongweb card
18 flowable task manualtask and receivetask
How to Algorithm Evaluation Methods
Etcd fast cluster building
MySQL built-in functions
Shardingsphere JDBC exception: no table route info
Integration of sentinel series Nacos to realize rule synchronization and persistence
Django uses redis to store sessions starting from 0
9. Errorstartevent and errorboundaryevent of error events
MySQL transactions and foreign keys
Top slide immersive dialog
Qmessagebox in pyqt5
Shardingsphere JDBC < bind table > avoid join Cartesian product