java.lang.Object
g2701_2800.s2730_find_the_longest_semi_repetitive_substring.Solution

public class Solution extends Object
2730 - Find the Longest Semi-Repetitive Substring.<p>Medium</p> <p>You are given a <strong>0-indexed</strong> string <code>s</code> that consists of digits from <code>0</code> to <code>9</code>.</p> <p>A string <code>t</code> is called a <strong>semi-repetitive</strong> if there is at most one consecutive pair of the same digits inside <code>t</code>. For example, <code>0010</code>, <code>002020</code>, <code>0123</code>, <code>2002</code>, and <code>54944</code> are semi-repetitive while <code>00101022</code>, and <code>1101234883</code> are not.</p> <p>Return <em>the length of the longest semi-repetitive substring inside</em> <code>s</code>.</p> <p>A <strong>substring</strong> is a contiguous <strong>non-empty</strong> sequence of characters within a string.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;52233&rdquo;</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> The longest semi-repetitive substring is &ldquo;5223&rdquo;, which starts at i = 0 and ends at j = 3.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;5494&rdquo;</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> s is a semi-reptitive string, so the answer is 4.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;1111111&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> The longest semi-repetitive substring is &ldquo;11&rdquo;, which starts at i = 0 and ends at j = 1.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 50</code></li> <li><code>'0' <= s[i] <= '9'</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • longestSemiRepetitiveSubstring

      public int longestSemiRepetitiveSubstring(String s)