File tree 2 files changed +39
-1
lines changed
2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,066 LeetCode solutions in JavaScript
1
+ # 1,067 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcode.com/ ] ( https://leetcode.com/ )
4
4
792
792
981|[ Time Based Key-Value Store] ( ./solutions/0981-time-based-key-value-store.js ) |Medium|
793
793
982|[ Triples with Bitwise AND Equal To Zero] ( ./solutions/0982-triples-with-bitwise-and-equal-to-zero.js ) |Hard|
794
794
983|[ Minimum Cost For Tickets] ( ./solutions/0983-minimum-cost-for-tickets.js ) |Medium|
795
+ 984|[ String Without AAA or BBB] ( ./solutions/0984-string-without-aaa-or-bbb.js ) |Medium|
795
796
985|[ Sum of Even Numbers After Queries] ( ./solutions/0985-sum-of-even-numbers-after-queries.js ) |Easy|
796
797
989|[ Add to Array-Form of Integer] ( ./solutions/0989-add-to-array-form-of-integer.js ) |Easy|
797
798
994|[ Rotting Oranges] ( ./solutions/0994-rotting-oranges.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 984. String Without AAA or BBB
3
+ * https://leetcode.com/problems/string-without-aaa-or-bbb/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given two integers a and b, return any string s such that:
7
+ * - s has length a + b and contains exactly a 'a' letters, and exactly b 'b' letters,
8
+ * - The substring 'aaa' does not occur in s, and
9
+ * - The substring 'bbb' does not occur in s.
10
+ */
11
+
12
+ /**
13
+ * @param {number } a
14
+ * @param {number } b
15
+ * @return {string }
16
+ */
17
+ var strWithout3a3b = function ( a , b ) {
18
+ let result = '' ;
19
+
20
+ while ( a > 0 || b > 0 ) {
21
+ if ( a > b && a > 0 && ! result . endsWith ( 'aa' ) ) {
22
+ result += 'a' ;
23
+ a -- ;
24
+ } else if ( b > 0 && ! result . endsWith ( 'bb' ) ) {
25
+ result += 'b' ;
26
+ b -- ;
27
+ } else if ( a > 0 ) {
28
+ result += 'a' ;
29
+ a -- ;
30
+ } else {
31
+ result += 'b' ;
32
+ b -- ;
33
+ }
34
+ }
35
+
36
+ return result ;
37
+ } ;
You can’t perform that action at this time.
0 commit comments