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

Return the maximum amount of splitted balanced strings.

Input:s = "RLRRLLRLRL"Output:4Explanation:s can be split into "RL", "RRLL", "RL", "RL", each substring contains same number of 'L' and 'R'.

Input:s = "RLLLLRRRLR"Output:3Explanation:s can be split into "RL", "LLLRRR", "LR", each substring contains same number of 'L' and 'R'.

Input:s = "LLLLRRRR"Output:1Explanation:s can be split into "LLLLRRRR".

Input:s = "RLRRRLLRLL"Output:2Explanation:s can be split into "RL", "RRRLLRLL", since each substring contains an equal number of 'L' and 'R'

- 1 <= s.length <= 1000
- s[i] = 'L' or 'R'

Solution:

class Solution { public int balancedStringSplit(String s) { int diff = 0, count = 0; int i = 0, n = s.length(); while (i < n) { char in = s.charAt(i); if (in == 'L') { diff ++; } else { diff --; } if (diff == 0) { count ++; } i ++; } return count; } }