Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6443f9f

Browse files
authoredOct 18, 2020
Create largest-substring-between-two-equal-characters.cpp
1 parent 2ba0b97 commit 6443f9f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
 
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int maxLengthBetweenEqualCharacters(string s) {
7+
int result = -1;
8+
vector<int> lookup(26, -1);
9+
for (int i = 0; i < size(s); ++i) {
10+
if (lookup[s[i] - 'a'] >= 0) {
11+
result = max(result, i - lookup[s[i] - 'a'] - 1);
12+
} else {
13+
lookup[s[i] - 'a'] = i;
14+
}
15+
}
16+
return result;
17+
}
18+
};

0 commit comments

Comments
 (0)
Please sign in to comment.