Skip to content

4Sum #16

@barretlee

Description

@barretlee

本题难度:★★

给定一个长度为 n 的整数数组 S,找出所有的非重复四元组 (a, b, c, d) 使得 a + b + c + d = target,如:

给定数组 S = [1, 0, -1, 0, -2, 2], target = 0,
那么输出结果为:

[
  [-1,  0, 0, 1],
  [-2, -1, 1, 2],
  [-2,  0, 0, 2]
]

要求:

  1. 输出的四元组按照顺序排列,即 a ≤ b ≤ c ≤ d;
  2. 最后的输出结果不存在重复元组.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions