当前位置:网站首页>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;
}
边栏推荐
- 【已解决】如何生成漂亮的静态文档说明页
- Construction plan of Zhuhai food physical and chemical testing laboratory
- Unity | 实现面部驱动的两种方式
- After 95, the CV engineer posted the payroll and made up this. It's really fragrant
- Dedecms plug-in free SEO plug-in summary
- Live video source code, realize local storage of search history
- Electrical data | IEEE118 (including wind and solar energy)
- Overview of Zhuhai purification laboratory construction details
- 基于DVWA的文件上传漏洞测试
- Zhuhai's waste gas treatment scheme was exposed
猜你喜欢

False breakthroughs in the trend of London Silver

Hcip---ipv6 experiment

Docker compose配置MySQL并实现远程连接

Vulhub vulnerability recurrence 75_ XStream

After 95, the CV engineer posted the payroll and made up this. It's really fragrant

XSS learning XSS lab problem solution

ThreeDPoseTracker项目解析

【SSRF-01】服务器端请求伪造漏洞原理及利用实例

Finding the nearest common ancestor of binary tree by recursion

Building core knowledge points
随机推荐
ctf. Show PHP feature (89~110)
Unity | two ways to realize facial drive
Mathematical modeling learning from scratch (2): Tools
IP storage and query in MySQL
[机缘参悟-39]:鬼谷子-第五飞箝篇 - 警示之二:赞美的六种类型,谨防享受赞美快感如同鱼儿享受诱饵。
MATLB | real time opportunity constrained decision making and its application in power system
Zhuhai laboratory ventilation system construction and installation instructions
Finding the nearest common ancestor of binary search tree by recursion
Docker compose配置MySQL并实现远程连接
3D视觉——4.手势识别(Gesture Recognition)入门——使用MediaPipe含单帧(Singel Frame)和实时视频(Real-Time Video)
FFT learning notes (I think it is detailed)
一圖看懂!為什麼學校教了你Coding但還是不會的原因...
Leetcode sword finger offer 59 - ii Maximum value of queue
基於DVWA的文件上傳漏洞測試
在产业互联网时代,将会凭借大的产业范畴,实现足够多的发展
How to get the PHP version- How to get the PHP Version?
伦敦银走势中的假突破
MATLB|实时机会约束决策及其在电力系统中的应用
Recursive method to realize the insertion operation in binary search tree
Development trend of Ali Taobao fine sorting model