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 — #2351 - First Letter to Appear Twice - LeetCode JavaScript Solutions

Back to all solutions

#2351 - First Letter to Appear Twice

Easy • View on LeetCode • View on GitHub
String Hash Table Bit Manipulation Counting

Problem Description

Given a string s consisting of lowercase English letters, return the first letter to appear twice.

Note:

  • A letter a appears twice before another letter b if the second occurrence of a is before the second occurrence of b.
  • s will contain at least one letter that appears twice.

Solution

/**
 * @param {string} s
 * @return {character}
 */
var repeatedCharacter = function(s) {
  const set = new Set();

  for (const char of s) {
    if (set.has(char)) return char;
    set.add(char);
  }
};
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.