Class Solution
-
- All Implemented Interfaces:
public final class Solution3703 - Remove K-Balanced Substrings.
Medium
You are given a string
sconsisting of'('and')', and an integerk.A string is k-balanced if it is exactly
kconsecutive'('followed bykconsecutive')', i.e.,'(' * k + ')' * k.For example, if
k = 3, k-balanced is"((()))".You must repeatedly remove all non-overlapping k-balanced substring from
s, and then join the remaining parts. Continue this process until no k-balanced substring exists.Return the final string after all possible removals.
Example 1:
Input: s = "(())", k = 1
Output: ""
Explanation:
k-balanced substring is
"()"Thus, the final string is
"".Example 2:
Input: s = "(()(", k = 1
Output: "(("
Explanation:
k-balanced substring is
"()"Thus, the final string is
"((".Example 3:
Input: s = "((()))()()()", k = 3
Output: "()()()"
Explanation:
k-balanced substring is
"((()))"Thus, the final string is
"()()()".Constraints:
<code>2 <= s.length <= 10<sup>5</sup></code>
sconsists only of'('and')'.1 <= k <= s.length / 2
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final StringremoveSubstring(String s, Integer k)-
-
Method Detail
-
removeSubstring
final String removeSubstring(String s, Integer k)
-
-
-
-