a334: Balanced String
標籤 :
通過比率 : 100% (3 人 / 3 人 ) (非即時)
評分方式:
Strictly

最近更新 : 2021-09-15 15:53

內容 :

Balanced strings are those that have an equal quantity of 'L' and 'R' characters.

Given a balanced string s, split it in the maximum amount of balanced strings.

Return the maximum amount of split balanced strings.

 

 

------------------------------------------

Constraints:

  • 1 <= s.length <= 1000
  • s[i] is either 'L' or 'R'.
  • s is a balanced string.
輸入說明
  • A string that have an equal quantity of 'L' and 'R' characters
輸出說明
  • Maximum amount of split balanced strings
範例輸入
RLRRLLRLRL
範例輸出
4
測資資訊:
記憶體限制: 64 MB
公開 測資點#0 (100%): 1.0s , <1K
提示 :

Explanation for example:

  • s can be split into "RL", "RRLL", "RL", "RL", each substring contains same number of 'L' and 'R'.

 

Hint:

  1. Loop from left to right maintaining a balance variable when it gets an L increase it by one otherwise decrease it by one.
  2. Whenever the balance variable reaches zero then we increase the answer by one.

 

標籤:
出處:
leetcode [編輯: will8467 (will8467) ]
編號 身分 題目 主題 人氣 發表日期
沒有發現任何「解題報告」