Skip to content

Commit 75a2880

Browse files
committed
Runtime: 125 ms (Top 10.81%) | Memory: 42.4 MB (Top 45.95%)
1 parent 77ce21f commit 75a2880

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
// Runtime: 125 ms (Top 10.81%) | Memory: 42.4 MB (Top 45.95%)
12
/**
23
* @param {number} a
34
* @param {number} b
45
* @return {string}
56
*/
67
var strWithout3a3b = function(a, b) {
78
let r = '';
8-
9+
910
let A = 'a', AA = A + A;
1011
let B = 'b', BB = B + B;
11-
12+
1213
while (a > 0 || b > 0) {
1314
if (a > b) {
1415
a = calculate(a, A, AA);
@@ -19,23 +20,23 @@ var strWithout3a3b = function(a, b) {
1920
a = calculate(a, A, AA, true);
2021
}
2122
}
22-
23+
2324
return r;
2425

2526
function calculate(v, s, ss, l = false) {
2627
if (l) {
2728
if (v > 0) {
2829
r += s, v -= 1;
2930
}
30-
31+
3132
return v;
3233
}
33-
34+
3435
let c = v >= 2 && r[r.length - 1] !== s;
35-
36+
3637
r += c ? ss : s;
3738
v -= c ? 2 : 1;
3839

3940
return v;
4041
}
41-
};
42+
};

0 commit comments

Comments
 (0)