Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2e9be88

Browse files
05-03-2024
1 parent 99434a2 commit 2e9be88

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎2024/03 - March/05-03-2024.cpp‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
3+
Author : Manas Rawat
4+
Date : 05/03/2024
5+
Problem : Minimum Length of String After Deleting Similar Ends
6+
Difficulty : Medium
7+
Problem Link : https://leetcode.com/problems/minimum-length-of-string-after-deleting-similar-ends/description/
8+
Video Solution : NA
9+
10+
*/
11+
12+
13+
class Solution {
14+
public:
15+
int minimumLength(string s) {
16+
int i = 0;
17+
int j = (int)s.size() - 1;
18+
19+
while(i < j and s[i] == s[j]){
20+
char x = s[i];
21+
22+
while(i < s.size() and s[i] == x) ++i;
23+
while(j > -1 and s[j] == x) --j;
24+
}
25+
26+
return max(0, j - i + 1);
27+
}
28+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /