Leetcode Problem 387. First Unique Character in a String

387. First Unique Character in a String

Leetcode Solutions

Using HashMap to Find First Non-Repeating Character

  1. Initialize a hash map to store the frequency of each character.
  2. Iterate over the string s, and for each character, increment its count in the hash map.
  3. Iterate over the string s again, and for each character, check its count in the hash map.
  4. If the count is 1 (the character is non-repeating), return the current index.
  5. If no non-repeating character is found, return -1 after the second iteration.
UML Thumbnail

Brute Force Search for First Non-Repeating Character

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...