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