当前位置:网站首页>Leetcode skimming questions_ Invert vowels in a string
Leetcode skimming questions_ Invert vowels in a string
2022-07-06 01:24:00 【Figure throne】
Title Description

Java resolvent
import java.util.*;
class Solution {
public String reverseVowels(String s) {
// ArrayList It is used to judge whether a character is in an array
Collection c = new ArrayList();
c.add('a');c.add('e');c.add('i');c.add('o');c.add('u');
c.add('A');c.add('E');c.add('I');c.add('O');c.add('U');
int head = 0;
int tail = s.length() - 1;
// Modifying a character in a string requires StringBuilder
StringBuilder s1 = new StringBuilder(s);
while(head < tail)
{
char a1 = s1.charAt(head);
char a2 = s1.charAt(tail);
if(!c.contains(a1))
{
head++;
}
else if(!c.contains(a2))
{
tail--;
}
else
{
s1.setCharAt(head, a2);
s1.setCharAt(tail, a1);
head++;
tail--;
}
}
String s2 = s1.toString();
return s2;
}
}
C Language solutions
int nocontains(char a)
{
if(a != 'a' && a != 'A' && a != 'e' && a != 'E' && a != 'i' && a != 'I' && a != 'o' && a != 'O' && a != 'u' && a != 'U')
{
return 1;
}
return 0;
}
char * reverseVowels(char * s){
int head = 0;
int tail;
tail = strlen(s) - 1;
while(head < tail)
{
char a;
char b;
a = s[head];
b = s[tail];
if(nocontains(a))
{
head++;
}
else if(nocontains(b))
{
tail--;
}
else
{
s[head] = b;
s[tail] = a;
head++;
tail--;
}
}
return s;
}
边栏推荐
- Exciting, 2022 open atom global open source summit registration is hot
- 037 PHP login, registration, message, personal Center Design
- How to get the PHP version- How to get the PHP Version?
- Pbootcms plug-in automatically collects fake original free plug-ins
- ThreeDPoseTracker项目解析
- c#网页打开winform exe
- Some features of ECMAScript
- 伦敦银走势中的假突破
- Loop structure of program (for loop)
- Xunrui CMS plug-in automatically collects fake original free plug-ins
猜你喜欢

ORA-00030

Building core knowledge points

Finding the nearest common ancestor of binary search tree by recursion

黄金价格走势k线图如何看?

Convert binary search tree into cumulative tree (reverse middle order traversal)

The growth path of test / development programmers, the problem of thinking about the overall situation

General operation method of spot Silver

普通人下场全球贸易,新一轮结构性机会浮出水面

Idea sets the default line break for global newly created files

Some features of ECMAScript
随机推荐
Daily practice - February 13, 2022
Huawei Hrbrid interface and VLAN division based on IP
How does Huawei enable debug and how to make an image port
Superfluid_ HQ hacked analysis
Mathematical modeling learning from scratch (2): Tools
Cglib dynamic agent -- example / principle
What is weak reference? What are the weak reference data types in ES6? What are weak references in JS?
在产业互联网时代,将会凭借大的产业范畴,实现足够多的发展
Tcpdump: monitor network traffic
WGet: command line download tool
Unity | two ways to realize facial drive
XSS learning XSS lab problem solution
普通人下场全球贸易,新一轮结构性机会浮出水面
[Yu Yue education] Liaoning Vocational College of Architecture Web server application development reference
leetcode刷题_平方数之和
视频直播源码,实现本地存储搜索历史记录
c#网页打开winform exe
Distributed base theory
Three methods of script about login and cookies
Leetcode 剑指 Offer 59 - II. 队列的最大值