当前位置:网站首页>剑指 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;
}
边栏推荐
- Xshell startup encountered "unable to continue code execution because mfc110.dll cannot be found"
- 【数据存储】浮点型数据在内存中的存储
- Make a simple page with the websql database of HTML5:
- Box model border
- sql中的Exists用法
- [advanced pointer I] character array & array pointer & pointer array
- Knee joint
- 动态线段树leetcode.699
- Chapter 3 registers (memory access)
- Code generation tool Autocode for XML Publishing
猜你喜欢

2022 safety officer-c certificate special operation certificate examination question bank and simulation examination

ISCSI详解(五)——ISCSI客户端配置实战

Regularization to limit the number of digits after the decimal point of an input number

2022 simulated examination platform operation of high voltage electrician work license question bank

Chapter 8 - two basic problems of data processing

Engineers learn music theory (I) try to understand music
![[GUI development] browsing function implementation model of image processing software](/img/37/2162a6047682b9cfc9b8b7c2488068.jpg)
[GUI development] browsing function implementation model of image processing software

Binlog in mysql:

Background color translucent
![[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
随机推荐
Centso8 installing mysql8.0 (Part 2)
Union selector
Install iptables services and open ports
Get last month, current time and next month
Domain name mapping to specified IP
When converting tensor to ndarray in tensorflow, the run or Eval function is constantly called in the loop, and the code runs more and more slowly!
[untitled] task3 multiple recall
(十二)交互组件Selectable
UMI packaging and subcontracting, and compressing to gzip
机器学习笔记 - 循环神经网络备忘清单
Audio and video engineer (Preliminary) (I) basic concepts of audio and video
【指針進階三】實現C語言快排函數qsort&回調函數
POI library update excel picture
Method to limit the input box to only numbers
Specify 404 and 500 error reporting pages.
2022 safety officer-c certificate special operation certificate examination question bank and simulation examination
[dynamic memory management] malloc & calloc and realloc and written test questions and flexible array
Summary of common character sets
《MATLAB 神经网络43个案例分析》:第8章 GRNN网络的预测----基于广义回归神经网络的货运量预测
第三章 寄存器 (内存访问)