当前位置: 首页 > news >正文

LeetCode75——Day15

文章目录

    • 一、题目
    • 二、题解

一、题目

1456. Maximum Number of Vowels in a Substring of Given Length

Given a string s and an integer k, return the maximum number of vowel letters in any substring of s with length k.

Vowel letters in English are ‘a’, ‘e’, ‘i’, ‘o’, and ‘u’.

Example 1:

Input: s = “abciiidef”, k = 3
Output: 3
Explanation: The substring “iii” contains 3 vowel letters.
Example 2:

Input: s = “aeiou”, k = 2
Output: 2
Explanation: Any substring of length 2 contains 2 vowels.
Example 3:

Input: s = “leetcode”, k = 3
Output: 2
Explanation: “lee”, “eet” and “ode” contain 2 vowels.

Constraints:

1 <= s.length <= 105
s consists of lowercase English letters.
1 <= k <= s.length

二、题解

利用滑动窗口进行判断

class Solution {
public:int maxVowels(string s, int k) {int n = s.length();unordered_map<char,int> map;map['a'] = 1;map['e'] = 1;map['i'] = 1;map['o'] = 1;map['u'] = 1;int count = 0;int res = 0;for(int i = 0;i < k;i++){if(map[s[i]] == 1) count++;}res = max(res,count);for(int i = k;i < n;i++){if(map[s[i - k]] == 1) count--;if(map[s[i]] == 1) count++;res = max(res,count);}return res;}
};
http://www.lryc.cn/news/205198.html

相关文章:

  • Qwt开发环境搭建(保姆级教程)
  • 【供应链】仓储、物流、车辆管理
  • 从另外一个进程中读取数据
  • 【FPGA零基础学习之旅#17】搭建串口收发与储存双口RAM系统
  • 建立Line类
  • 10_集成学习方法:随机森林、Boosting
  • 工业通信网关常用的工业通信协议
  • 如何将音频与视频分离
  • 【antd】form表单为空校验失效 form.item.rules传入非所需的api属性时,引起为空自动验证失效问题
  • 数据可视化的常见工具
  • 不希望你的数据在云中?关闭iPhone或Mac上的iCloud
  • 10 个最佳免费 PDF 压缩工具软件
  • LVS+keepalived高可用集群
  • 虚拟化 vs. 裸金属:K8s 部署环境架构与特性对比
  • C语言程序设计——题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
  • Python中使用cv2.resize()函数批量自定义缩放图像尺寸
  • 驱动开发5 阻塞IO实例、IO多路复用
  • ElasticSearch:实现高效数据搜索与分析的利器!项目中如何应用落地,让我带你实操指南。
  • 2023了,是时候使用pnpm了!
  • asp.net文档管理系统VS开发sqlserver数据库web结构c#编程Microsoft Visual Studio
  • Parallels Client for Mac:改变您远程控制体验的革命性软件
  • Julia数组详解
  • 用事务代码查看视图的函数
  • LuatOS-SOC接口文档(air780E)--libcoap - coap数据处理
  • js控制checkbox单选,获取checkbox的值,选中checkbox
  • MYSQL(事务+锁+MVCC+SQL执行流程)理解(2)
  • ubuntu tools
  • LeetCode 155. 掷骰子等于目标和的方法数:动态规划
  • PostgreSQL数据库从入门到精通系列之五:安装时序数据库TimescaleDB的详细步骤
  • 软件测试(五)自动化 selenium