Skip to content

Commit

Permalink
Sync LeetCode submission - Generate a String With Characters That Hav…
Browse files Browse the repository at this point in the history
…e Odd Counts (javascript)
  • Loading branch information
alexbriannaughton committed Jan 26, 2024
1 parent 5eaee4c commit 03b4760
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @param {number} n
* @return {string}
*/
var generateTheString = function(n) {
const nIsEven = n % 2 === 0;
let output = nIsEven ? 'a' : '';
const len = nIsEven ? n - 1 : n;
for (let i = 0; i < len; i++) {
output += 'b';
}
return output;

//return n % 2 === 0
// ? 'a'.repeat(n - 1) + 'b'
// : 'a'.repeat(n);
};

0 comments on commit 03b4760

Please sign in to comment.