Skip to content

Commit 30ffd8f

Browse files
committed
Add solution #984
1 parent 54fa072 commit 30ffd8f

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,066 LeetCode solutions in JavaScript
1+
# 1,067 LeetCode solutions in JavaScript
22

33
[https://leetcode.com/](https://leetcode.com/)
44

@@ -792,6 +792,7 @@
792792
981|[Time Based Key-Value Store](./solutions/0981-time-based-key-value-store.js)|Medium|
793793
982|[Triples with Bitwise AND Equal To Zero](./solutions/0982-triples-with-bitwise-and-equal-to-zero.js)|Hard|
794794
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|
795796
985|[Sum of Even Numbers After Queries](./solutions/0985-sum-of-even-numbers-after-queries.js)|Easy|
796797
989|[Add to Array-Form of Integer](./solutions/0989-add-to-array-form-of-integer.js)|Easy|
797798
994|[Rotting Oranges](./solutions/0994-rotting-oranges.js)|Medium|
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
};

0 commit comments

Comments
 (0)