mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create 3_jzf.cpp
This commit is contained in:
parent
efb59f18ec
commit
e999d09913
39
LeetCode-CN/3_jzf.cpp
Normal file
39
LeetCode-CN/3_jzf.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
class Solution {
|
||||
public:
|
||||
int lengthOfLongestSubstring(string s) {
|
||||
int num =1;
|
||||
int max =0;
|
||||
if(s.length()==1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
for(size_t i =0;i<s.length();i++)
|
||||
{
|
||||
|
||||
for(size_t j=i+1;j<s.length();j++)
|
||||
{
|
||||
int flag =0;
|
||||
for(size_t k =i;k<j;k++)
|
||||
{
|
||||
if(s[j]==s[k])
|
||||
{
|
||||
flag =1;
|
||||
break;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
if(num>max)
|
||||
{
|
||||
max =num;
|
||||
}
|
||||
if(flag ==1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
num =1;
|
||||
}
|
||||
num =1;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user