Skip to content

Commit edc7714

Browse files
committed
代码修改
1 parent 3f08ba7 commit edc7714

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lengthOfLongestSubstring.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
int lengthOfLongestSubstring(string s) {
55
int max=0;
66
string subs=s.substr(0,1);
7+
if(s.size()==1) return 1;
78
for(int i =1;i<s.size();++i){
89
auto pos=subs.find(s[i]);
9-
if (pos==npos) {s.append(s[i]);continue;}
10-
max=(subs.size()>max)? subs.size(),max;
11-
subs.erase(0,npos);
12-
subs.append(s[i])
10+
if (pos==-1) {subs.append(s,i,1);continue;}
11+
max=(subs.size()>max)? subs.size():max;
12+
subs.erase(0,pos+1);
13+
subs.append(s,i,1);
1314
}
15+
max=(subs.size()>max)? subs.size():max;
1416
return max;
15-
}
17+
}

0 commit comments

Comments
 (0)