Re: [闲聊] 每日LeetCode

楼主: Rushia (みけねこ的鼻屎)   2022-11-04 10:05:10
345. Reverse Vowels of a String
给你一个字串要你把他的元音字母都反转。
Example:
Input: s = "hello"
Output: "holle"
思路:
1.写一个判断字母是否是元音的函数。
2.双指标找到左边和右边的第一个元音。
3.把两个元音交换之后继续往字串里面紧缩直到 i == j。
JavaCode:
class Solution {
public String reverseVowels(String s) {
int n = s.length();
char[] chars = s.toCharArray();
int i = 0, j = n - 1;
while (i < j) {
while (i < j && !isVowel(chars[i])) i++;
while (i < j && !isVowel(chars[j])) j
作者: PyTorch (屁眼火炬)   2022-11-04 10:07:00
这提男得我会耶话说你表情符号怎么打的这么小的
楼主: Rushia (みけねこ的鼻屎)   2022-11-04 10:11:00
☹ = / smile 去空格
作者: TNPSCG (TNP)   2022-11-04 10:16:00
刷这种题目有在管效率的吗?还是效率就纯粹自我挑战而已
楼主: Rushia (みけねこ的鼻屎)   2022-11-04 10:18:00
简单的我会想办法优化 难的基本上以先解出来为主easy以上的有赢50%基本上都可以接受
作者: TNPSCG (TNP)   2022-11-04 10:21:00
原来看的到和其他人的比较结果
作者: pandix (面包屌)   2022-11-04 10:26:00
大师
作者: itoumashiro (佩可咪口爱的结晶)   2022-11-04 10:26:00

Links booklink

Contact Us: admin [ a t ] ucptt.com