java: add «1750. Minimum Length of String After Deleting Similar Ends»

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2024-03-06 00:11:13 +01:00
parent 4061ff562b
commit b9f735f1e8
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -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;
}
}