gpt4 book ai didi

algorithm - 乘积等于 N 的子数组

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:08:18 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Sub array that produces a given sum and product

给定一个数组,找到一个子数组,其中元素的乘积等于 N。这是我的尝试

P = 1
Make an another array arr1
for i = 0 to n-1
arr1[i] = P
P *= arr1[i]
put elements, index of arr1 in hash table
for i = 0 to n-1
search in hash table for P/arr1[i]
if found
return [i+1 ... index in hash table]

这是正确的吗?任何其他更简单的解决方案。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com