Create 3_jzf.cpp

This commit is contained in:
Kirigaya Kazuto 2018-06-20 23:10:54 +08:00 committed by GitHub
parent efb59f18ec
commit e999d09913
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

39
LeetCode-CN/3_jzf.cpp Normal file
View 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;
}
};