Class Solution

java.lang.Object
g0401_0500.s0466_count_the_repetitions.Solution

public class Solution extends Object
466 - Count The Repetitions.<p>Hard</p> <p>We define <code>str = [s, n]</code> as the string <code>str</code> which consists of the string <code>s</code> concatenated <code>n</code> times.</p> <ul> <li>For example, <code>str == [&quot;abc&quot;, 3] ==&quot;abcabcabc&quot;</code>.</li> </ul> <p>We define that string <code>s1</code> can be obtained from string <code>s2</code> if we can remove some characters from <code>s2</code> such that it becomes <code>s1</code>.</p> <ul> <li>For example, <code>s1 = &quot;abc&quot;</code> can be obtained from <code>s2 = &quot;ab**dbe**c&quot;</code> based on our definition by removing the bolded underlined characters.</li> </ul> <p>You are given two strings <code>s1</code> and <code>s2</code> and two integers <code>n1</code> and <code>n2</code>. You have the two strings <code>str1 = [s1, n1]</code> and <code>str2 = [s2, n2]</code>.</p> <p>Return <em>the maximum integer</em> <code>m</code> <em>such that</em> <code>str = [str2, m]</code> <em>can be obtained from</em> <code>str1</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s1 = &ldquo;acb&rdquo;, n1 = 4, s2 = &ldquo;ab&rdquo;, n2 = 2</p> <p><strong>Output:</strong> 2</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s1 = &ldquo;acb&rdquo;, n1 = 1, s2 = &ldquo;acb&rdquo;, n2 = 1</p> <p><strong>Output:</strong> 1</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s1.length, s2.length <= 100</code></li> <li><code>s1</code> and <code>s2</code> consist of lowercase English letters.</li> <li><code>1 <= n1, n2 <= 10<sup>6</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • getMaxRepetitions

      public int getMaxRepetitions(String s1, int n1, String s2, int n2)