{"size": 431, "ext": "js", "max_stars_repo_path": "src/leetcode/string/387_first_unique_character_in_a_string.js", "max_stars_repo_name": "atbulbs/leetcode_playground", "max_stars_repo_stars_event_min_datetime": "2020-07-31T15:19:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-31T15:19:01.000Z", "max_issues_repo_path": "src/leetcode/string/387_first_unique_character_in_a_string.js", "max_issues_repo_name": "atbulbs/leetcode_playground", "max_issues_repo_issues_event_min_datetime": "2020-05-09T16:33:53.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-09T16:33:53.000Z", "max_forks_repo_path": "src/leetcode/string/387_first_unique_character_in_a_string.js", "max_forks_repo_name": "atbulbs/leetcode_playground", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 19.5909090909, "max_line_length": 39, "alphanum_fraction": 0.4988399072}
/**
 * @param {string} s
 * @return {number}
 */
var firstUniqChar = function(s) {
  const memory = {}
  for (let i = 0; i < s.length; i++) {
    const curStr = s[i]
    if (memory[curStr] === undefined) {
      memory[curStr] = 1
    } else if (memory[curStr]) {
      memory[curStr]++
    }
  }
  for (let j = 0; j < s.length; j++) {
    const curStr = s[j]
    if (memory[curStr] === 1) {
      return j
    }
  }
  return -1
};