当前位置:网站首页>剑指 Offer II 016. 不含重复字符的最长子字符串-滑动窗口
剑指 Offer II 016. 不含重复字符的最长子字符串-滑动窗口
2022-06-12 08:56:00 【Mr Gao】
剑指 Offer II 016. 不含重复字符的最长子字符串
给定一个字符串 s ,请你找出其中不含有重复字符的 最长连续子字符串 的长度。
示例 1:
输入: s = “abcabcbb”
输出: 3
解释: 因为无重复字符的最长子字符串是 “abc”,所以其长度为 3。
示例 2:
输入: s = “bbbbb”
输出: 1
解释: 因为无重复字符的最长子字符串是 “b”,所以其长度为 1。
示例 3:
输入: s = “pwwkew”
输出: 3
解释: 因为无重复字符的最长子串是 “wke”,所以其长度为 3。
请注意,你的答案必须是 子串 的长度,“pwke” 是一个子序列,不是子串。
示例 4:
输入: s = “”
输出: 0
解题代码如下:
int lengthOfLongestSubstring(char * s){
int r[128];
int i=0;
if(strlen(s)==0){
return 0;
}
for(i=0;i<128;i++){
r[i]=0;
}
int max=0;
int left=0,right=0;
while(s[right]!='\0'){
printf("%d",left);
if(r[s[right]]==0){
r[s[right]]=1;
if(right-left>max){
max=right-left;
}
right++;
}
else{
while(s[left]!=s[right]&&left<=right){
printf("%d",left);
r[s[left]]=0;
left++;
}
r[s[left]]=0;
left++;
}
}
return max+1;
}
边栏推荐
- 正则校验用户名
- Binlog in mysql:
- 43 cas d'analyse du réseau neuronal MATLAB: chapitre 7 régression du réseau RBF - - réalisation de la régression fonctionnelle non linéaire
- Gets the number of occurrences of a character in a string
- 第五章-[bx]和Loop指令
- Wechat applet image saving function
- The classic dog contract of smart contract (I)
- JS to refresh the page after loading
- 2022 melting welding and thermal cutting test questions and answers
- [compilation principle] understand BNF
猜你喜欢
![[character set 7] what are the wide character codes and multi byte codes of Chinese characters](/img/8c/6d375d90234e6094b6930c2cefefa1.png)
[character set 7] what are the wide character codes and multi byte codes of Chinese characters

2022 low voltage electrician retraining question bank and online simulation examination

根据有效期显示距离当前还剩多少天有效期

EIP-1559

Does database and table splitting cause reading diffusion problems? How to solve it?

Composition of box model

Background color translucent
![[character set 9] will GBK be garbled when copied to unicode?](/img/dc/c9ec4a90355d30479f23fdead4b349.png)
[character set 9] will GBK be garbled when copied to unicode?
![[GUI development] browsing function implementation model of image processing software](/img/37/2162a6047682b9cfc9b8b7c2488068.jpg)
[GUI development] browsing function implementation model of image processing software

Graphic analysis of viewbox in SVG
随机推荐
Audio and video engineer (Preliminary) (I) basic concepts of audio and video
【字符集九】gbk拷贝到Unicode会乱码?
长安链节点证书、角色、权限管理介绍
2022.6.9-----leetcode.497
第四章-第一个程序
Inheritance of row height
ISCSI详解(五)——ISCSI客户端配置实战
2022.6.9-----leetcode. four hundred and ninety-seven
《MATLAB 神经网络43个案例分析》:第8章 GRNN网络的预测----基于广义回归神经网络的货运量预测
Background fixing effect
Flink传入自定义的参数或配置文件
Engineers learn music theory (II) scale and tendency
[character set 8] char8_ t、char16_ t、char32_ t、wchar、char
Chapter 7 - more flexible location of memory addresses
xshell启动遇到“由于找不到mfc110.dll,无法继续执行代码的解决方法”
网页中加载二次元3D虚拟主播源码(1:项目介绍和源码)
【字符集六】宽字符串和多字节字符互转
了结非对称密钥
POI library update excel picture
Implementing architecture caching in MySQL under redis server environment