From a8f8e8d875f320d57f44863c38154066036c549a Mon Sep 17 00:00:00 2001 From: Cool <747682928@qq.com> Date: Mon, 4 Nov 2024 15:55:15 +0800 Subject: [PATCH] =?UTF-8?q?2024/11/4=20=E7=81=B5=E8=8C=B6=E9=A2=98?= =?UTF-8?q?=E5=8D=95=20=E6=BB=91=E5=8A=A8=E7=AA=97=E5=8F=A3=20=E7=9B=B8?= =?UTF-8?q?=E5=90=91=E5=8F=8C=E6=8C=87=E9=92=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sliding_windows/Num1750.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/com/cool/ling_cha_mount/sliding_windows/Num1750.java diff --git a/src/main/java/com/cool/ling_cha_mount/sliding_windows/Num1750.java b/src/main/java/com/cool/ling_cha_mount/sliding_windows/Num1750.java new file mode 100644 index 0000000..57c5ab9 --- /dev/null +++ b/src/main/java/com/cool/ling_cha_mount/sliding_windows/Num1750.java @@ -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; + } +}