. [Swift] LeetCode1190 reverse substring between each pair of brackets | Reverse Substrings Between Each Pair of Parentheses

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤ micro-channel public number: to dare (WeiGanTechnologies)
➤ blog Park address: San-ching Wing Chi ( https://www.cnblogs.com/strengthen/ )
➤GitHub address: https://github.com/strengthen/LeetCode
➤ original address: HTTPS: //www.cnblogs. com / strengthen / p / 11521663.html
➤ If the address is not a link blog Park Yong Shan Chi, it may be crawling author of the article.
➤ text has been modified update! Click strongly recommended that the original address read! Support authors! Support the original!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

Given a string s that consists of lower case English letters and brackets. 

Reverse the strings in each pair of matching parentheses, starting from the innermost one.

Your result should not contain any bracket.

 

 

Example 1:

Input: s = "(abcd)"
Output: "dcba"

Example 2:

Input: s = "(u(love)i)"
Output: "iloveu"

Example 3:

Input: s = "(ed(et(oc))el)"
Output: "leetcode"

Example 4:

Input: s = "a(bcdefghijkl(mno)p)q"
Output: "apmnolkjihgfedcbq"

 

Constraints:

  • 0 <= s.length <= 2000
  • s only contains lower case English characters and parentheses.
  • It's guaranteed that all parentheses are balanced.

Given a string  s(containing only lowercase letters and parentheses).

Please order from outside to the brackets, each pair of the matching string inversion layer by layer in parentheses, and returns the final result.

Note that your results should not contain any parentheses.

 

Example 1:

Input: s = "(abcd)" 
Output: "dcba"

Example 2:

Input: s = "(u (love ) i)" 
Output: "iloveu"

Example 3:

Input: s = "(ed (et (oc)) el)" 
Output: "leetcode"

Example 4:

Input: s = "a (bcdefghijkl ( mno) p) q" 
Output: "apmnolkjihgfedcbq"

 

prompt:

  • 0 <= s.length <= 2000
  • s Only lowercase letters and brackets
  • We ensure that all of the brackets come in pairs.

Guess you like

Origin www.cnblogs.com/strengthen/p/11521663.html