Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 755 Bytes

_2796. Repeat String.md

File metadata and controls

39 lines (29 loc) · 755 Bytes

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : July 09, 2024

Last updated : July 09, 2024


Related Topics : N/A

Acceptance Rate : 93.06 %


Solutions

JavaScript

/**
 * @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 : '');
}