Skip to content

Commit d5c8253

Browse files
authored
Create length-of-the-longest-alphabetical-continuous-substring.cpp
1 parent 00a1477 commit d5c8253

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
// string
5+
class Solution {
6+
public:
7+
int longestContinuousSubstring(string s) {
8+
int result = 0;
9+
for (int i = 0, l = 0; i < size(s); ++i) {
10+
++l;
11+
if (i + 1 == size(s) || s[i] + 1 != s[i + 1]) {
12+
result = max(result, l);
13+
l = 0;
14+
}
15+
}
16+
return result;
17+
}
18+
};

0 commit comments

Comments
 (0)