package com.fishercoder.solutions;

/**
 * 1180. Count Substrings with Only One Distinct Letter
 *
 * Given a string S, return the number of substrings that have only one distinct letter.
 *
 * Example 1:
 * Input: S = "aaaba"
 * Output: 8
 * Explanation: The substrings with one distinct letter are "aaa", "aa", "a", "b".
 * "aaa" occurs 1 time.
 * "aa" occurs 2 times.
 * "a" occurs 4 times.
 * "b" occurs 1 time.
 * So the answer is 1 + 2 + 4 + 1 = 8.
 *
 * Example 2:
 * Input: S = "aaaaaaaaaa"
 * Output: 55
 *
 * Constraints:
 * 1 <= S.length <= 1000
 * S[i] consists of only lowercase English letters.
 * */
public class _1180 {
    public static class Solution1 {
        public int countLetters(String S) {
            int count = 0;
            for (int i = 0, j = 1; j < S.length() && i <= j; ) {
                while (j < S.length() && S.charAt(i) == S.charAt(j)) {
                    j++;
                }
                count += countTimes(S.substring(i, j));
                i += S.substring(i, j).length();
            }
            return count;
        }

        private int countTimes(String str) {
            int len = str.length();
            int times = 0;
            while (len > 0) {
                times += len--;
            }
            return times;
        }
    }
}

@@ -33,587 +33,8 @@
 s;%0A%0A
-/**%0A * 1180. Count Substrings with Only One Distinct Letter%0A *%0A * Given a string S, return the number of substrings that have only one distinct letter.%0A *%0A * Example 1:%0A * Input: S = %22aaaba%22%0A * Output: 8%0A * Explanation: The substrings with one distinct letter are %22aaa%22, %22aa%22, %22a%22, %22b%22.%0A * %22aaa%22 occurs 1 time.%0A * %22aa%22 occurs 2 times.%0A * %22a%22 occurs 4 times.%0A * %22b%22 occurs 1 time.%0A * So the answer is 1 + 2 + 4 + 1 = 8.%0A *%0A * Example 2:%0A * Input: S = %22aaaaaaaaaa%22%0A * Output: 55%0A *%0A * Constraints:%0A * 1 %3C= S.length %3C= 1000%0A * S%5Bi%5D consists of only lowercase English letters.%0A * */%0A
 publ

refactor 1180