GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • LeetCodeJavascript.com
  • Star on GitHub

This view

  • Original page
  • New address

GeezerVison is showing leetcodejavascript.com — #1374 - Generate a String With Characters That Have Odd Counts - LeetCode JavaScript Solutions

Back to all solutions

#1374 - Generate a String With Characters That Have Odd Counts

Easy • View on LeetCode • View on GitHub
String

Problem Description

Given an integer n, return a string with n characters such that each character in such string occurs an odd number of times.

The returned string must contain only lowercase English letters. If there are multiples valid strings, return any of them.

Solution

/**
 * @param {number} n
 * @return {string}
 */
var generateTheString = function(n) {
  return 'a'.repeat(n % 2 ? n : n - 1) + (n % 2 ? '' : 'z');
};
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.