Leetcode 1119. Remove Vowels from a String, Java解法

亚麻 OA 2019 题目 Most Common Word Prison Cells After N Days K Closest Points to Origin Reorder Log Files Partition Labels Min Cost to Add New Roads Min distance to remove the obstacle Roll Dice Min Cost to Con... 阅读详情

Given a string S, remove the vowels 'a', 'e', 'i', 'o', and 'u' from it, and return the new string.

Example 1:

Input: "leetcodeisacommunityforcoders"
Output: "ltcdscmmntyfrcdrs"

Example 2:

Input: "aeiou"
Output: ""

Note:

  1. S consists of lowercase English letters only.
  2. 1 <= S.length <= 1000

Approach #1 我的解法,new StringBuilder()

public class Solution {
    public String removeVowels(String S) {
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<S.length();i++){
            if(S.charAt(i)-'a'!=0 && S.charAt(i)-'e'!=0&&S.charAt(i)-'i'!=0&&S.charAt(i)-'o'!=0&&S.charAt(i)-'u'!=0)
                sb.append(S.charAt(i));
        }
        return sb.toString();
    }
}

Approach #2 string.replaceAll()

public String removeVowels(String S) {
        return S.replaceAll("[a,e,i,o,u]", "");
    }

学习 string.replaceAll()

replaceAll() 方法使用给定的参数 replacement 替换字符串所有匹配给定的正则表达式的子字符串。

语法

public String replaceAll(String regex, String replacement)

参数

  • regex -- 匹配此字符串的正则表达式。

  • newChar -- 用来替换每个匹配项的字符串。

返回值

成功则返回替换的字符串,失败则返回原始字符串。

Leetcode 250. Count Univalue Subtrees 谷歌面试, Java解法详解 这是一道谷歌会考的题目 Given a binary tree, count the number of uni-value subtrees. A Uni-value subtree means all nodes of the subtree have the same value. Example : Input: root = [5,1,5,5,5,null,5] ... 阅读详情

相关推荐

17、深入探索Excel VBA自定义函数的创建与应用

本文深入探讨了Excel VBA中自定义函数的创建与应用,涵盖数组公式、返回错误值、处理不定数量参数、模拟SUM函数、扩展日期处理等功能。详细介绍了如何通过CVErr返回真实错误值、使用ParamArray实现灵活参数传递、构建可处理多种数据类型的MYSUM函数,以及开发支持早期日期的扩展函数。同时提供了调试技巧、插入函数对话框处理和MacroOptions方法优化用户体验的方法,并给出实际应用建议与未来学习方向,帮助用户高效利用VBA提升Excel自动化能力。

python9snake的博客 53

5027. Remove Vowels From a String

题目描述: Given a stringS, remove the vowels'a','e','i','o', and'u'from it, and return the new string. Example 1: Input: "leetcodeisacommunityforcoders" Output: "ltcdscmmntyfrcdrs" Example 2:...

wchzh2015的博客 469

Vowels_And_Consonants_Counter:元音和辅音计数器Java任务

元音和辅音计数器Java任务 只需计算«text.txt»文件中不同字母的数量即可。

LeetCode 1119. Remove Vowels from a String--C++,Java,Python解法

LeetCode题解专栏:LeetCode题解 我做的所有的LeetCode的题目都放在这个专栏里,大部分题目Java和Python的解法都有。 欢迎大家关注我的专栏。 题目地址:1119. Remove Vowels from a String Given a string S, remove the vowels ‘a’, ‘e’, ‘i’, ‘o’, and ‘u’ from it, ...

个人博客 885

告别混乱!在Unity中为Best MQTT v3设计清晰的服务层:配置、连接、订阅发布模块拆分指南

本文详细介绍了如何在Unity中使用Best MQTT v3插件构建清晰的服务层架构,包括配置管理、连接服务、订阅管理和发布服务的模块化拆分。通过解耦设计、事件驱动和接口抽象,提升代码可维护性和可测试性,适用于物联网和实时通信开发场景。

weixin_30576827的博客 357

ROS中tf2_ros::Buffer.lookupTransform的正确使用姿势:从踩坑到填坑

本文深入解析了ROS中tf2_ros::Buffer.lookupTransform接口的正确使用方法,重点剖析了因tf2_ros::TransformListener生命周期管理不当导致的经典问题。文章提供了从理解Buffer与Listener共生关系、类成员设计黄金法则到参数详解与异常处理的完整避坑指南,并给出了构建健壮坐标变换工具类的实战方案,帮助开发者稳定实现机器人坐标系变换。

weixin_29253711的博客 134

【LeetCode】1119. Remove Vowels from a String 解题报告(C++)

作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录题目描述题目大意解题方法判断字符是否是aeiou日期 题目地址:https://leetcode-cn.com/problems/remove-vowels-from-a-string/ 题目描述 Given a string S, remove the vowe...

负雪明烛 976

Xshell 连接 kali 虚拟机教程

启动ssh服务,启动后重新查看ssh服务状态,如下图active(running)正常。至此便可以直接使用Xshell登录kali系统了。至此虚拟机已经可以上网。-查看ssh服务状态。

qq_40726937的博客 2219

【Leetcode】1119. Remove Vowels from a String

题目地址: https://leetcode.com/problems/remove-vowels-from-a-string/ 给定一个字符串,去掉其所有元音字母后返回。代码如下: import java.util.HashSet; import java.util.Set; public class Solution { public String removeVowels(Stri...

数学、算法爱好者的博客 202

2017–2024年中国10米/20米分辨率水稻种植分布数据集

摘要:本数据集提供2017-2024年中国23个省级行政区的水稻种植分布数据,包含单季稻和双季稻分类(GeoTIFF格式,WGS84坐标系)。5个省份分辨率为20米,其余为10米,基于Sentinel卫星数据和TWDTW方法生成。数据公开共享(7.99GB),使用需注明来源并引用相关文献(DOI:10.12199/nesdc.ecodb.rs.2025.012)。涉及学科包括遥感、生态学和地理学,研究成果需发送至国家生态科学数据中心备案。

国科大硕士在读,分享Python/GEE/Matlab/R专业代码实践,涵盖数据分析、算法开发与应用技巧等,以代码会友。 1381

【四足机器人项目实战】cheetah 3/mini运动控制工程解读(附C++代码)

系列文章目录 提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加 TODO:写完再整理 文章目录系列文章目录前言一、主程序入口1.代码流程2.终端设置信息提示二、用MiniCheetahHardwareBridge类构造一个hw的对象并初初始化1.2.3.4.三、运行硬件桥驱动【MiniCheetahHardwareBridge】1.2.3.4.四、1.2.3.4.总结参考资料 前言 认知有限,望大家多多包涵,有什么问题也希望能够与大家多交流,共同成长! 本文先对cheetah3/m

qq_35635374的博客 2615

LeetCode 1119. Remove Vowels from a String

class Solution { public String removeVowels(String S) { StringBuilder sb = new StringBuilder(); for(char c: S.toCharArray()){ if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){ continue; .

qq_31361913的博客 151

37、OpenMP:并行编程的强大工具

本文详细介绍了 OpenMP 的核心功能和使用方法,包括执行环境例程、线程同步与协调机制,如关键区域、屏障、原子操作、归约子句、刷新构造和锁机制。此外,还提供了多个实践练习,涵盖矩阵乘法的并行实现、任务池与流水线模式的应用、读写锁的扩展与移植,以及客户端-服务器模式的实现与优化。通过这些内容,读者可以全面掌握 OpenMP 在并行编程中的实际应用与性能优化技巧。

www00的博客 101

leetcode 1119. 删去字符串中的元音--Java和Python语言的实现

问题描述 给你一个字符串 S,请你删去其中的所有元音字母( 'a','e','i','o','u'),并返回这个新字符串。 例子: 输入:"leetcodeisacommunityforcoders" 输出:"ltcdscmmntyfrcdrs" 解题思路 首先定义一个新的输出字符串res,接着循环遍历输出字符串S判断S中的每一个字符串是否为元音字母,如果不是元音字母则存入res中。 Java 代码 public String removeVowels(String S){ char[] arr

xiekengli8279的博客 1189

华为OD机考双机位C卷 - 最左侧冗余覆盖子串 (Java)

华为OD机考双机位C卷 - 最左侧冗余覆盖子串 (Java), 提供Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。

算法大师! 58

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

Leetcode 1119:删去字符串中的元音(超详细的解法!!!)

给你一个字符串 S,请你删去其中的所有元音字母( 'a','e','i','o','u'),并返回这个新字符串。 示例 1: 输入:"leetcodeisacommunityforcoders" 输出:"ltcdscmmntyfrcdrs" 示例 2: 输入:"aeiou" 输出:"" 提示: S 仅由小写英文字母组成。 1 <= S.length <= 1000 解题思路 通...

coordinate的博客 1639

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Leetcode 1086. High Five Java 解法

先吐槽一下这个难度,咋也不能是easy啊,和其他easy的不在一个量级。 Given a list of scores of different students, return the average score of each student'stop five scoresinthe order of each student's id. Each entryitems[i]h...

YuanTheCoder的博客 1473

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

Leetcode 1051. Height Checker, Java解法

Students are asked to stand in non-decreasing order of heights for an annual photo. Return the minimum number of students not standing in the right positions. (This is the number of students that mu...

YuanTheCoder的博客 649

Leetcode 1108. Defanging an IP Address, Java解法

Given a valid (IPv4) IPaddress, return a defanged version of that IP address. AdefangedIP addressreplaces every period"."with"[.]". Example 1: Input: address = "1.1.1.1" Output: "1[.]1[....

YuanTheCoder的博客 574

Java中 Queue队列的用法及例子

1. Usage 用法 // "static void main" must be defined in a public class. public class Main { public static void main(String[] args) { // 1. Initialize a queue. Queue<Integer> q...

YuanTheCoder的博客 557

Leetcode 509. Fibonacci Number , Java 解法

TheFibonacci numbers, commonly denotedF(n)form a sequence, called theFibonacci sequence, such that each number is the sum of the two preceding ones, starting from0and1. That is, F(0) = 0, F(...

YuanTheCoder的博客 503

Leetcode 977. Squares of a Sorted Array, Java解法

Given an array of integersAsorted in non-decreasing order,return an array of the squares of each number,also in sorted non-decreasing order. Example 1: Input: [-4,-1,0,3,10] Output: [0,1,9,16,1...

YuanTheCoder的博客 497

狗家 Online Assessment

License Key Formatting Unique Email Addresses Fruit Into Baskets Odd Even Jump Maximum Area Serving Cake Min Days to Bloom Fill Matrix Compare Strings Largest Subarray Length K Decreasing Sub...

YuanTheCoder的博客 470

Leetcode 922. Sort Array By Parity II , Java解法

Given an arrayAof non-negative integers, half of the integers in A are odd, and half of the integers are even. Sort the array so that wheneverA[i]is odd,iis odd; and wheneverA[i]is even,iis...

YuanTheCoder的博客 444

Leetcode [141, 142] Linked List Cycle,java解法

141 Linked List Cycle Given a linked list, determine if it has a cycle in it. To represent a cycle in the given linked list, we use an integerposwhich represents the position (0-indexed)in the l...

YuanTheCoder的博客 419
上一篇: Leetcode [724, 747,66] Array专题 (1)
下一篇: Leetcode 283. Move Zeroes java解法
YuanTheCoder
博客等级 码龄9年 2粉丝 34原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值