8000 how about this for two-sum · Issue #1 · chihungyu1116/leetcode-javascript · GitHub
[go: up one dir, main page]

Skip to content
how about this for two-sum #1
Closed
@jhanink

Description

@jhanink
var twoSum = function (nums, target) {
  var hash = {}; 
  for (var i=0;i<nums.length;i++) {
    var found = hash[nums[i]];
    if (found) {
      return [found, i+1]; 
    } else {
      hash[target-nums[i]] = i+1;
    }     
  }
  return [];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0