当前位置:网站首页>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;
}
边栏推荐
- Unity | 实现面部驱动的两种方式
- Five challenges of ads-npu chip architecture design
- [Yu Yue education] Liaoning Vocational College of Architecture Web server application development reference
- Yii console method call, Yii console scheduled task
- 282. Stone consolidation (interval DP)
- JVM_ 15_ Concepts related to garbage collection
- Mlsys 2020 | fedprox: Federation optimization of heterogeneous networks
- Three methods of script about login and cookies
- Condition and AQS principle
- SSH login is stuck and disconnected
猜你喜欢
Vulhub vulnerability recurrence 74_ Wordpress
Introduction to robotics I. spatial transformation (1) posture, transformation
MUX VLAN configuration
Pbootcms plug-in automatically collects fake original free plug-ins
XSS learning XSS lab problem solution
DOM introduction
Differences between standard library functions and operators
晶振是如何起振的?
Docker compose configures MySQL and realizes remote connection
3D model format summary
随机推荐
The growth path of test / development programmers, the problem of thinking about the overall situation
MATLB|实时机会约束决策及其在电力系统中的应用
leetcode刷题_平方数之和
How to extract MP3 audio from MP4 video files?
Recommended areas - ways to explore users' future interests
VMware Tools安装报错:无法自动安装VSock驱动程序
基于DVWA的文件上传漏洞测试
Blue Bridge Cup embedded stm32g431 - the real topic and code of the eighth provincial competition
Four commonly used techniques for anti aliasing
CocoaPods could not find compatible versions for pod 'Firebase/CoreOnly'
Live video source code, realize local storage of search history
A Cooperative Approach to Particle Swarm Optimization
直播系统代码,自定义软键盘样式:字母、数字、标点三种切换
A picture to understand! Why did the school teach you coding but still not
Mathematical modeling learning from scratch (2): Tools
[the most complete in the whole network] |mysql explain full interpretation
Code Review关注点
Finding the nearest common ancestor of binary tree by recursion
282. Stone consolidation (interval DP)
Leetcode 208. Implement trie (prefix tree)