2796. Repeat String
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : July 09, 2024
Last updated : July 09, 2024
Related Topics : N/A
Acceptance Rate : 93.0 %
/**
* @param {number} times
* @return {string}
*/
String.prototype.replicate = function(times) {
if (times === 1) {
return this;
}
let half = this.replicate(Math.floor(times / 2));
return half + half + (times % 2 == 1 ? this : '');
}