From 127d23b479030ad8c355866effacd57035d67c62 Mon Sep 17 00:00:00 2001 From: Cool <747682928@qq.com> Date: Wed, 30 Oct 2024 17:13:41 +0800 Subject: [PATCH] =?UTF-8?q?2024/10/30=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=E6=9C=80?= =?UTF-8?q?=E7=9F=AD/=E6=9C=80=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sliding_windows/Num1358.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main/java/com/cool/ling_cha_mount/sliding_windows/Num1358.java diff --git a/src/main/java/com/cool/ling_cha_mount/sliding_windows/Num1358.java b/src/main/java/com/cool/ling_cha_mount/sliding_windows/Num1358.java new file mode 100644 index 0000000..ef31a98 --- /dev/null +++ b/src/main/java/com/cool/ling_cha_mount/sliding_windows/Num1358.java @@ -0,0 +1,30 @@ +package com.cool.ling_cha_mount.sliding_windows; + +/** + * Created with IntelliJ IDEA. + * + * @Author: Cool + * @Date: 2024/10/30/17:07 + * @Description: + */ +public class Num1358 { + public int numberOfSubstrings(String s) { + int res = 0; + int left = 0; + int[] arr = new int[3]; + for (int i = 0; i < s.length(); i++) { + ++arr[s.charAt(i) - 'a']; + boolean is = true; + for (int a : arr) { + is = a != 0; + if (!is) break; + } + if (is) { + do { + res += s.length() - i; + } while (--arr[s.charAt(left++) - 'a'] != 0); + } + } + return res; + } +}