贪心算法应用 Aug 13, 2020 • cbtpro 分割平衡字符串 var balancedStringSplit = function(s) { let count = 0; let balance = 0; for(let i = 0; i < str.length; i++) { if (str[i] === 'L') balance++; else balance--; if (balance === 0) count++; } return count; }; balancedStringSplit('LLRRLRRL'); 地铁自动售票机找零