hxtree/sumfinder

此程序允许传入一个整数数组,然后输出所有相加等于总和的数对。

安装: 2

依赖关系: 0

建议者: 0

安全性: 0

星星: 0

关注者: 3

分支: 0

开放问题: 0

类型:项目

v0.1.0 2020-02-25 07:21 UTC

This package is auto-updated.

Last update: 2024-09-26 12:21:48 UTC


README

SumFinder 接受一个整数数组,并找出哪些操作数相加等于所需的值。

CI Codacy Badge

用法

require __DIR__ . '/../vendor/autoload.php';

$sum_finder = new SumFinder();
$sum_finder->setSumValue(10);
$sum_finder->setIntArray(1,1,2,4,4,5,5,5,6,7,9);

/*
 * output all pairs (includes duplicates and the reversed order pairs)
 * [1,9], [1,9], [4,6], [4,6], [5,5], [5,5], [5,5], [5,5], [5,5], [5,5]
 */
echo $sum_finder->getAllPairs() . PHP_EOL;

/*
 * output unique pairs only once (removes the duplicates but includes the reversed ordered pairs)
 * [1,9], [4,6], [5,5], [6,4], [9,1]
 */
echo $sum_finder->getUniquePairs() . PHP_EOL;

/*
 * output the same combo pair only once (removes the reversed ordered pairs)
 * [1,9], [4,6], [5,5]
 */
echo $sum_finder->getComboPairs() . PHP_EOL;

安装

通过 Composer

SumFinder 可在 Packagist 上找到。

使用 Composer 安装

composer require hxtree/sumfinder

示例

了解如何通过我们的 文档 使用 SumFinder。