2024/11/4 灵茶题单 滑动窗口 相向双指针
This commit is contained in:
parent
47c4452ced
commit
a8f8e8d875
|
@ -0,0 +1,27 @@
|
||||||
|
package com.cool.ling_cha_mount.sliding_windows;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA.
|
||||||
|
*
|
||||||
|
* @Author: Cool
|
||||||
|
* @Date: 2024/11/04/15:54
|
||||||
|
* @Description: 1750. 删除字符串两端相同字符后的最短长度
|
||||||
|
*/
|
||||||
|
public class Num1750 {
|
||||||
|
public int minimumLength(String s) {
|
||||||
|
int left = 0;
|
||||||
|
int right = s.length() - 1;
|
||||||
|
while (left < right && s.charAt(left) == s.charAt(right)) {
|
||||||
|
char c=s.charAt(left);
|
||||||
|
left++;
|
||||||
|
right--;
|
||||||
|
while (left <= right && s.charAt(left) == c) {
|
||||||
|
left++;
|
||||||
|
}
|
||||||
|
while (left <= right && s.charAt(right) == c) {
|
||||||
|
right--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return right - left + 1;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue