goden1624

package
v0.0.0-...-b071cee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2023 License: GPL-3.0 Imports: 1 Imported by: 0

README

面试题 16.24.数对和

1. 题目描述

设计一个算法,找出数组中两数之和为指定值的所有整数对。一个数只能属于一个数对。

示例 1:

输入: nums = [5,6,5], target = 11
输出: [[5,6]]

示例 2:

输入: nums = [5,6,5,6], target = 11
输出: [[5,6],[5,6]]

提示:

  • nums.length <= 100000

标签 数组 哈希表 双指针 计数 排序

2. 解题

先排序,初始化双指针分别指向头尾,设双指针分别为p,q

若arr[p] + arr[q] > target, q左移 若arr[p] + arr[q] < target, p右移 若arr[p] + arr[q] == target, 记录,p右移,q左移

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL