给定大小为N的数组的三个数的最大乘积 [英] Max product of the three numbers for a given array of size N

查看:127
本文介绍了给定大小为N的数组的三个数的最大乘积的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个程序来找到给定大小N的数组的三个数的最大乘积.有什么有效的算法吗?我只需要知道算法步骤.我认为没有一种算法适用于所有测试用例.谢谢!FYI数组可以包含+ ve,-ve或零个元素)

I need to write a program to find the Max product of three numbers for a given array of size N. Is there any effective algorithm for this? I just need to know the algorithm steps. Non of algorithms that i thought works for all the test cases. Thanks! FYI Array may contains +ve, -ve, or zero elements)

推荐答案

查找数组中的三个最大数字(n1,n2,n3)和两个最小的数字(m1,m2).

Find the three largest numbers in the array (n1, n2, n3) and the two smallest numbers (m1, m2).

答案是n1 x n2 x n3或n1 x m1 x m2

The answer is either n1 x n2 x n3 or n1 x m1 x m2

这篇关于给定大小为N的数组的三个数的最大乘积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆