Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    3084 - Count Substrings Starting and Ending with Given Character\.

    Medium

    You are given a string s and a character c. Return the total number of substrings of s that start and end with c.

    Example 1:

    Input: s = "abada", c = "a"

    Output: 6

    Explanation: Substrings starting and ending with "a" are: <code>"<ins> a </ins>bada"</code>, <code>"<ins> aba </ins>da"</code>, <code>"<ins> abada </ins>"</code>, <code>"ab<ins> a </ins>da"</code>, <code>"ab<ins> ada </ins>"</code>, <code>"abad<ins> a </ins>"</code>.

    Example 2:

    Input: s = "zzz", c = "z"

    Output: 6

    Explanation: There are a total of 6 substrings in s and all start and end with "z".

    Constraints:

    • <code>1 <= s.length <= 10<sup>5</sup></code>

    • s and c consist only of lowercase English letters.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Long countSubstrings(String s, Character c)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait