386 · Longest Substring with At Most K Distinct Characters最多有k个不同字符的最长子字符串
链接:https://www.lintcode.com/problem/386/description
https://mp.weixin.qq.com/s?__biz=MzU2OTUyNzk1NQ==&mid=2247491103&idx=1&sn=8d9a2ed68a7dd31bb2aeb50ffe8fa4c8&source=41#wechat_redirect
题解:
class Solution {
public:/*** @param s: A string* @param k: An integer* @return: An integer*/int lengthOfLongestSubstringKDistinct(string &s, int k) {// write your code hereif (s.size() <= 0) {return 0;}int right = 0;int left = 0;int max_len = 0;std::unordered_map<char, int> table;while (right < s.size()) {++table[s[right]];if (table.size() > k) {while (left <s.size() && table.size() > k) {if (--table[s[left]] == 0) {table.erase(s[left]);}++left;}}max_len = max(max_len, right-left+1);++right;}return max_len;}
};
386 · Longest Substring with At Most K Distinct Characters最多有k个不同字符的最长子字符串相关推荐
- [LeetCode] 159. Longest Substring with At Most Two Distinct Characters 最多有两个不同字符的最长子串...
Given a string S, find the length of the longest substring T that contains at most two distinct char ...
- [LeetCode] Longest Substring with At Most Two Distinct Characters 最多有两个不同字符的最长子串...
Given a string S, find the length of the longest substring T that contains at most two distinct char ...
- [LeetCode] Longest Substring with At Most K Distinct Characters 最多有K个不同字符的最长子串...
Given a string, find the length of the longest substring T that contains at most k distinct characte ...
- LeetCode 159. Longest Substring with At Most Two Distinct Characters --Java,C++,Python解法
题目地址:Longest Substring with At Most Two Distinct Characters - LeetCode Given a string s , find the l ...
- leetcode Longest Substring with At Most Two Distinct Characters 滑动窗口法
题目解析 代码如下 题目解析 这一题是一道会员的题目,题目介绍如下: Given a string, find the length of the longest substring T that c ...
- 【算法】159题 Longest Substring with at Most Two Distinct Characters 最大的子串
1.概述 给定一个字符串.查找一个最长子序列,这个子序列中重复的字符最多包含2个. 此问题和 [算法]剑指 Offer 48. 最长不含重复字符的子字符串 问题很相似. 2.方案 2.1 双指针 pu ...
- LeetCode 340. Longest Substring with At Most K Distinct Characters
原题链接在这里:https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters/ 题目: Give ...
- Longest Substring With At Most K Distinct Characters
Given a string, find the length of the longest substring T that contains at most k distinct characte ...
- 【Lintcode】1375. Substring With At Least K Distinct Characters
题目地址: https://www.lintcode.com/problem/substring-with-at-least-k-distinct-characters/description 给定一 ...
最新文章
- SAP PM 初级系列10 - 维护通知单相关的配置
- java23中设计模式——结构模式——Composite(组合)
- mysql8.0导出带数据的库表_MySQL8.0数据库导出与备份
- python实现简单的api接口-使用Python编写API接口和使用API接口
- 出错页面webpar的t删除
- mysql主从复制深入研究_mysql主从复制原理,深入探讨
- wince linux 性能,wince remote call profiler(性能分析)
- 五一高铁票难抢?用RPA机器人试试!
- 微软发布关于 Surface Pro 3 TPM 绕过漏洞的安全公告
- 关于vue中next和Tick(nextTick)的一点理解
- 男子造出山寨ATM机 盗信息做假卡取钱13万
- ligerui+json_002_Grid用法、属性总结
- 丰收互联蓝牙key怎么开机_蓝牙UKEY使用说明
- iphonex蓝牙打不开转圈_多人反应iPhone X蓝牙连接时遇到问题
- Photoshop安装方法
- 实现Pomodoro计时器的Vue组件
- android ios 微信 备份通讯录备份通讯录,苹果手机号码怎么备份 微信导入联系人号码...
- LeetCode-1225. 报告系统状态的连续日期(困难)
- 计算机工程应用是什么期刊,计算机工程类期刊汇总
- 安卓文件传输工具 Android File Transfer mac