博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(LeetCode)给定一个字符串,请你找出其中不含有重复字符的最长子串 的长度。
阅读量:3924 次
发布时间:2019-05-23

本文共 884 字,大约阅读时间需要 2 分钟。

力扣

给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。

class Solution {
public: int lengthOfLongestSubstring(string s) {
int i = 1; int pos = 0; string sub; sub = s.substr(0); cout<<
= 1) {
while (s[i] != '\0') {
sub = s.substr(pos, length); // cout << sub << endl; if (sub.find(s[i]) == -1) {
//在当前子串中没有 length++; max = (max > length) ? max : length; // cout << s[i]<<" "<
<< " " << int(sub.find(s[i])) <<" pos="<
<
= i - pos) ? 1 : 0; if (flag == 1) {
max = (max > length) ? max : length; } else {
max = (max > p + 1) ? max : p + 1; } length = i - p - pos; pos = pos + p + 1; // printf("@pos=%d p=%d i=%d length=%d max=%d\n", pos, p, i, length, max); } i++; } max = (max > length) ? max : length; return max; } else return 0; }};

转载地址:http://ceugn.baihongyu.com/

你可能感兴趣的文章
NET问答: 为什么仅有 getter 的属性,还可以在构造函数中赋值 ?
查看>>
WPF TextBox限制只能输入数字的两种方法
查看>>
【荐】牛逼的WPF动画库:XamlFlair
查看>>
如何绕过 TPM 2.0 安装 Windows 11 操作系统?
查看>>
为WPF播放GIF伤神不?
查看>>
.NET Core with 微服务 - Elastic APM
查看>>
生产力提升! 自己动手自定义Visual Studio 2019的 类创建模板,制作简易版Vsix安装包...
查看>>
考虑用Task.WhenAll
查看>>
关于面试,避开这几点,成功几率更大~~~
查看>>
堵俊平:开放治理是开源社区的终极之路 | DEV. Together 2021 中国开发者生态峰会...
查看>>
Linux实操--实用指令Day3
查看>>
Linux实操--实用指令Day4
查看>>
Linux实操--实用指令Day3
查看>>
spring+springboot认识
查看>>
Leetcode 136. 只出现一次的数字
查看>>
Leetcode 11. 盛最多水的容器
查看>>
Leetcode 121. 买卖股票的最佳时机
查看>>
Leetcode 123. 买卖股票的最佳时机 III
查看>>
Leetcode 24. 两两交换链表中的节点
查看>>
Leetcode 100. 相同的树
查看>>