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

Canoe CAPL TCP通信避坑指南:从OnTcpConnect回调不触发到Socket句柄管理

本文详细解析了Canoe CAPL中TCP通信的常见问题与解决方案,包括OnTcpConnect回调不触发的三大原因、Socket句柄管理的内存泄漏风险、数据发送截断规则等。通过实战案例和代码示例,帮助开发者规避TCP通信中的典型陷阱,提升车载网络测试的稳定性和可靠性。

weixin_26976635的博客 358

在没有信用卡的情况下怎么申请谷歌云(Google Cloud)?

这笔额度足够用来跑一台云服务器、部署小型网站,甚至可以尝试 AI、机器学习等项目。但问题来了——想要拿到这 300 美元,你必须先通过支付方式验证。默认选项就是绑定一张国际信用卡(Visa、MasterCard 之类),然而不少人没有信用卡,或者信用卡无法支持国际支付,结果就卡在注册第一步。很多人会疑惑:既然是送额度,为什么还要绑卡?原因其实很简单:谷歌需要确认你是真实用户,而不是批量注册薅羊毛;通过支付验证,后续如果你用完 300 美元额度,可以直接进行付费使用;

m0_74824483的博客 5651

【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

信奥编程启蒙 3068:【例13.3】时间差

现在给出一个时间,单位是秒,要求按照电子表格式输出,输出保证不会超过 2424 小时。3067:【例13.2】 电子表。把时间转化成电子表格式输出。电子表上的时间显示方法形如。

900

【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

YOLO11的持续学习:如何在不遗忘旧数据的情况下学习新类别

类增量学习(Class-Incremental Learning, CIL)是持续学习(Continual Learning)的一个重要分支,它指的是模型在不遗忘已学旧类别知识的前提下,逐步学习新类别的能力。与传统机器学习假设所有数据一次可用不同,类增量学习更贴近现实世界应用场景——新的类别数据往往会随着时间推移逐步出现。 举个例子,假设我们已经训练好一个YOLOv11模型用于检测"猫"和"狗"两种动物,现在需要让模型新增识别"兔子"的能力。传统方法需要收集所有类别(猫、狗、兔子)的数据重新训练,而类增量

本博客聚焦 YOLOv11 全流程落地,涵盖架构优化、数据集处理、训练技巧与多场景部署,兼及国产数据库、Java 开发与 AI 模型应用,内容兼顾理论与工程实践,为开发者提供系统干货,助力高效提升技术能力。 1966

DMC-E 系列总线控制卡----雷赛板卡介绍(十七)

低的速度平稳地接近目标位置,降低运动部件对接触点的冲击。设置插补目标位置,插补方向,以确定插补动作。圆形区域限位,即运动仅在用户设定的圆形范围内进行,超出这个范围,运动会依据设定。首先,用户需要绑定两个轴进而确定该功能所处的坐标系。仅支持平面圆形限位,不支持空间圆形限位。径,可以确定该区域在坐标系中的位置。)运动开始前,用户应当将旋转轴调整到与插补曲线的起点位置相切的角度;可以配合椭圆插补或圆弧插补运动,实现跟随轴的旋转运动角度与曲线当前。外,其它运动形式若开始运动时在限位区域外,则禁止运动;

A_nanda的博客 651

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

基于 Python + Flask + Echarts 的疫情监控系统

基于 Python + Flask + Echarts 的疫情监控系统

743

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

06 - 深度学习处理器原理

深度学习处理器的重要性在于它们可以加速深度学习任务的执行,从而推动了人工智能的发展。传统的通用处理器虽然可以执行深度学习任务,但它们不够高效,需要消耗大量的能量和时间。深度学习处理器通过硬件加速和特定设计来优化深度学习任务的执行,从而可以提高执行效率、降低能耗和加速训练和推断过程。 深度学习处理器的发展也推动了深度学习算法的创新,因为算法的发展需要硬件的支持和驱动。同时,深度学习处理器的出现也促进了更广泛的应用场景,包括自动驾驶、人脸识别、语音识别、图像识别等领域。因此,深度学习处理器的重要性不仅在于加速

m0_51339444的博客 752

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

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

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

coordinate的博客 1639

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

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

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

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、付费专栏及课程。

余额充值