当前位置:网站首页>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;
}
边栏推荐
- Convert binary search tree into cumulative tree (reverse middle order traversal)
- Kotlin basics 1
- 黄金价格走势k线图如何看?
- MySQL learning notes 2
- MYSQL---查询成绩为前5名的学生
- How to see the K-line chart of gold price trend?
- File upload vulnerability test based on DVWA
- c#网页打开winform exe
- Leetcode1961. Check whether the string is an array prefix
- Leetcode 208. Implement trie (prefix tree)
猜你喜欢
Superfluid_ HQ hacked analysis
MUX VLAN configuration
SSH login is stuck and disconnected
How does the crystal oscillator vibrate?
Docker compose configures MySQL and realizes remote connection
Huawei Hrbrid interface and VLAN division based on IP
About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)
Blue Bridge Cup embedded stm32g431 - the real topic and code of the eighth provincial competition
Four dimensional matrix, flip (including mirror image), rotation, world coordinates and local coordinates
leetcode刷题_验证回文字符串 Ⅱ
随机推荐
ORA-00030
Differences between standard library functions and operators
Three methods of script about login and cookies
PHP error what is an error?
晶振是如何起振的?
Some features of ECMAScript
Recursive method converts ordered array into binary search tree
视频直播源码,实现本地存储搜索历史记录
FFT learning notes (I think it is detailed)
Unity | 实现面部驱动的两种方式
In the era of industrial Internet, we will achieve enough development by relying on large industrial categories
Finding the nearest common ancestor of binary tree by recursion
Redis' cache penetration, cache breakdown, cache avalanche
282. Stone consolidation (interval DP)
WGet: command line download tool
电气数据|IEEE118(含风能太阳能)
Obstacle detection
Leetcode1961. 检查字符串是否为数组前缀
Introduction to robotics I. spatial transformation (1) posture, transformation
c#网页打开winform exe