Skip to content

两数之和 #1

@Clear2

Description

@Clear2
func towSum(nums [4]int, target int) []int {
	m := make(map[int]int)

	for i := 0; i < len(nums); i++ {
		key := target - nums[i]

		if _, ok := m[key]; ok {
			return []int{m[key], i}
		}

		m[nums[i]] = i
	}
	return nil
}

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