We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6751089 commit 47d444eCopy full SHA for 47d444e
src/984-string-without-aaa-or-bbb/index.js
@@ -0,0 +1,32 @@
1
+/**
2
+ * @param {number} A
3
+ * @param {number} B
4
+ * @return {string}
5
+ */
6
+var strWithout3a3b = function (A, B) {
7
+ let res = '';
8
+ const arr = [
9
+ { label: 'a', value: A },
10
+ { label: 'b', value: B },
11
+ ];
12
+
13
+ while (arr[0].value > 0 || arr[1].value > 0) {
14
+ arr.sort((x, y) => x.value - y.value);
15
+ const [min, max] = arr;
16
17
+ if (
18
+ res.length >= 2 &&
19
+ res[res.length - 1] === max.label &&
20
+ res[res.length - 2] === max.label
21
+ ) {
22
+ res += min.label;
23
+ min.value--;
24
+ continue;
25
+ }
26
27
+ res += max.label;
28
+ max.value--;
29
30
31
+ return res;
32
+};
0 commit comments