avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • Resume
  • Archives
  • Categories
  • Photos
  • Music



{{ date }}

{{ time }}

avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • 主页
  • Resume
  • Archives
  • Categories
  • Photos
  • Music

345. Voice letter in the reverse string

  2024-01-01        
字数统计: 175字   |   阅读时长: 1min

topic:

2023-03-13 (1).png
345. Voice letter in the reverse string.md

Thought:

Write two methods,Watch the reminder of the three leaves of the palace water,Can be made with dual pointers,See if both the elements of both ends are vowel letters。 Improved two editions。

Code:

Double pointer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution:
def reverseVowels(self, s: str) -> str:
vowels = 'aeiouAEIOU'
start = 0
end = len(s) - 1
while start < end:
while s[end] not in vowels and start < end:
end -= 1
while s[start] not in vowels and start < end:
start += 1
if s[start] in vowels and s[end] in vowels:
s[start], s[end] = s[end], s[start]
start += 1
end -= 1
return ''.join(s)
String operation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution:
def reverseVowels(self, s: str) -> str:
s = list(s)
vowels = 'aeiouAEIOU'
ans = []
for i in s:
if i in vowels:
ans.append(i)
a = ''
for i in range(len(s)):
if s[i] in vowels:
a += ans.pop()
else:
a += s[i]
return ''.join(a)
  • Python
  • answer

扫一扫,分享到微信

微信分享二维码
350.The intersection of two array
445.Two numbersII
目录
  1. 1. topic:
  2. 2. Thought:
  3. 3. Code:

150 篇 | 131.7k
次 | 人
这里自动载入天数这里自动载入时分秒
2022-2025 loong loong | 新南威尔士龙龙号