Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ffd6e50

Browse files
authored
Create 1750-minimum-length-of-string-after-deleting-similar-ends.java
1 parent 01156b4 commit ffd6e50

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public int minimumLength(String s) {
3+
int l = 0;
4+
int r = s.length() - 1;
5+
6+
while (l < r && s.charAt(l) == s.charAt(r)) {
7+
char temp = s.charAt(l);
8+
while (l <= r && s.charAt(l) == temp)
9+
l++;
10+
while (l <= r && s.charAt(r) == temp)
11+
r--;
12+
}
13+
14+
return (r - l + 1);
15+
}
16+
}

0 commit comments

Comments
 (0)