Skip to content

Files

Latest commit

Zanger67/leetcodeZanger67/leetcode
Zanger67/leetcode
and
Zanger67/leetcode
Jan 20, 2025
8d4889c · Jan 20, 2025

History

History
39 lines (29 loc) · 754 Bytes

_2796. Repeat String.md

File metadata and controls

39 lines (29 loc) · 754 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.0 %


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