File tree 2 files changed +32
-1
lines changed
2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,402 LeetCode solutions in JavaScript
1
+ # 1,403 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
947
947
1218|[ Longest Arithmetic Subsequence of Given Difference] ( ./solutions/1218-longest-arithmetic-subsequence-of-given-difference.js ) |Medium|
948
948
1219|[ Path with Maximum Gold] ( ./solutions/1219-path-with-maximum-gold.js ) |Medium|
949
949
1220|[ Count Vowels Permutation] ( ./solutions/1220-count-vowels-permutation.js ) |Hard|
950
+ 1221|[ Split a String in Balanced Strings] ( ./solutions/1221-split-a-string-in-balanced-strings.js ) |Easy|
950
951
1222|[ Queens That Can Attack the King] ( ./solutions/1222-queens-that-can-attack-the-king.js ) |Medium|
951
952
1223|[ Dice Roll Simulation] ( ./solutions/1223-dice-roll-simulation.js ) |Hard|
952
953
1224|[ Maximum Equal Frequency] ( ./solutions/1224-maximum-equal-frequency.js ) |Hard|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1221. Split a String in Balanced Strings
3
+ * https://leetcode.com/problems/split-a-string-in-balanced-strings/
4
+ * Difficulty: Easy
5
+ *
6
+ * Balanced strings are those that have an equal quantity of 'L' and 'R' characters.
7
+ *
8
+ * Given a balanced string s, split it into some number of substrings such that:
9
+ * - Each substring is balanced.
10
+ *
11
+ * Return the maximum number of balanced strings you can obtain.
12
+ */
13
+
14
+ /**
15
+ * @param {string } s
16
+ * @return {number }
17
+ */
18
+ var balancedStringSplit = function ( s ) {
19
+ let result = 0 ;
20
+ let balance = 0 ;
21
+
22
+ for ( const char of s ) {
23
+ if ( char === 'R' ) balance ++ ;
24
+ else balance -- ;
25
+
26
+ if ( balance === 0 ) result ++ ;
27
+ }
28
+
29
+ return result ;
30
+ } ;
You can’t perform that action at this time.
0 commit comments