java: add «1750. Minimum Length of String After Deleting Similar Ends»
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
4061ff562b
commit
b9f735f1e8
1 changed files with 20 additions and 0 deletions
|
@ -0,0 +1,20 @@
|
||||||
|
class Solution {
|
||||||
|
public int minimumLength(String s) {
|
||||||
|
int i = 0;
|
||||||
|
int j = s.length() - 1;
|
||||||
|
|
||||||
|
while (i < j && s.charAt(i) == s.charAt(j)) {
|
||||||
|
var c = s.charAt(i);
|
||||||
|
|
||||||
|
while (i <= j && s.charAt(i) == c) {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (j > i && s.charAt(j) == c) {
|
||||||
|
--j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return j - i + 1;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue