问题是给定一个整数数组和一个长度L,找到一个长度为L的子数组,使得所有整数的乘积是最大的。示例:输入:{4,1,-7,-8, 9},3输出:{-7,-8,9}
我写了一个非常粗糙和逻辑上有缺陷的代码,没有给出任何合理的输出。也许有人能给我指个正确的方向
public class ProductProblem {
/*
* Given an array of integers and a length L, find a sub-array of length L such that the products of all integers are the biggest.
Exampl
我一直试图在数组之间生成所有可能的组合,比如a、b、c、x、y、z,其中最后3 (x、y、z)可以是数组或浮动。由于有了有用的注释和答案,这项任务得以完成(BTW,以更一般的方式,接受数组和浮点数)
from typing import Union, Sequence
import numpy as np
from numbers import Real
def cartesian_product(*arrays: np.ndarray) -> np.ndarray:
"""
See
https://stackoverflow.com