"Simplicity can't be bought later, it must be earned from the start" -- DB
public class Solution { public int BalancedStringSplit(string s) { var balanceCount = 0; var balanceDetector = 0; foreach (var c in s) { balanceDetector += c == 'L' ? 1 : -1; balanceCount += balanceDetector == 0 ? 1 : 0; } return balanceCount; } }
No comments:
Post a Comment