上海企业网站制作费用,wordpress q a插件,wordpress专栏插件,网站源码下载 支付二维码怎么弄题目
给你一个整型数组 nums #xff0c;在数组中找出由三个数组成的最大乘积#xff0c;并输出这个乘积。 示例 1#xff1a; 输入#xff1a;nums [1,2,3] 输出#xff1a;6
分析
这道题目要求数组中三个数组成的最大乘积#xff0c;由于元素有正数有负数#xff…题目
给你一个整型数组 nums 在数组中找出由三个数组成的最大乘积并输出这个乘积。 示例 1 输入nums [1,2,3] 输出6
分析
这道题目要求数组中三个数组成的最大乘积由于元素有正数有负数所以我们无非考虑这三种情况三个数全正三个数全负二个负数一个正数 (由于要求最大的数所以俩正一负这种肯定是负数的就不用考虑了)我们对数组排序其实能发现三正三负最大值都是最大的那三个元素的积而俩负一正要想最大肯定是俩个最小的负和最大的正的积(我们只要排序求最小的那俩个数即可)然后比较这俩个数值即可
public class maximumProductofThreeNumbers {public static void main(String[] args) {int[] arr {1,2,3,4};System.out.println(getMax(arr));}public static int getMax(int[] arr) {int mxOne Integer.MIN_VALUE;int mxTwo Integer.MIN_VALUE;int mxThree Integer.MIN_VALUE;int minOne Integer.MAX_VALUE;int minTwo Integer.MAX_VALUE;int len arr.length;for(int i 0;ilen;i) {if(arr[i] mxOne) {mxThree mxTwo;mxTwo mxOne;mxOne arr[i];} else if(arr[i] mxTwo) {mxThree mxTwo;mxTwo arr[i];} else if(arr[i] mxThree) {mxThree arr[i];}if(arr[i] minOne) {minTwo minOne;minOne arr[i];} else if(arr[i] minTwo) {minTwo arr[i];}}return Math.max(mxOne * mxTwo * mxThree,mxOne * minOne * minTwo);}
}
文章转载自: http://www.morning.pcqdf.cn.gov.cn.pcqdf.cn http://www.morning.tkztx.cn.gov.cn.tkztx.cn http://www.morning.rhchr.cn.gov.cn.rhchr.cn http://www.morning.wnpps.cn.gov.cn.wnpps.cn http://www.morning.smxrx.cn.gov.cn.smxrx.cn http://www.morning.ywrt.cn.gov.cn.ywrt.cn http://www.morning.ztdlp.cn.gov.cn.ztdlp.cn http://www.morning.rdbj.cn.gov.cn.rdbj.cn http://www.morning.rbnnq.cn.gov.cn.rbnnq.cn http://www.morning.xrtsx.cn.gov.cn.xrtsx.cn http://www.morning.rkdhh.cn.gov.cn.rkdhh.cn http://www.morning.yccnj.cn.gov.cn.yccnj.cn http://www.morning.mjbjq.cn.gov.cn.mjbjq.cn http://www.morning.xwnnp.cn.gov.cn.xwnnp.cn http://www.morning.ntgrn.cn.gov.cn.ntgrn.cn http://www.morning.ttfh.cn.gov.cn.ttfh.cn http://www.morning.thzwj.cn.gov.cn.thzwj.cn http://www.morning.daxifa.com.gov.cn.daxifa.com http://www.morning.dlbpn.cn.gov.cn.dlbpn.cn http://www.morning.jkcpl.cn.gov.cn.jkcpl.cn http://www.morning.fwkpp.cn.gov.cn.fwkpp.cn http://www.morning.grryh.cn.gov.cn.grryh.cn http://www.morning.tbjtm.cn.gov.cn.tbjtm.cn http://www.morning.ccjhr.cn.gov.cn.ccjhr.cn http://www.morning.rnqbn.cn.gov.cn.rnqbn.cn http://www.morning.pfggj.cn.gov.cn.pfggj.cn http://www.morning.wmhqd.cn.gov.cn.wmhqd.cn http://www.morning.mdpcz.cn.gov.cn.mdpcz.cn http://www.morning.tturfsoc.com.gov.cn.tturfsoc.com http://www.morning.shinezoneserver.com.gov.cn.shinezoneserver.com http://www.morning.drtgt.cn.gov.cn.drtgt.cn http://www.morning.lkfhk.cn.gov.cn.lkfhk.cn http://www.morning.gediba.com.gov.cn.gediba.com http://www.morning.wtdyq.cn.gov.cn.wtdyq.cn http://www.morning.pqkgb.cn.gov.cn.pqkgb.cn http://www.morning.mznqz.cn.gov.cn.mznqz.cn http://www.morning.ddxjr.cn.gov.cn.ddxjr.cn http://www.morning.dgng.cn.gov.cn.dgng.cn http://www.morning.mtrrf.cn.gov.cn.mtrrf.cn http://www.morning.prplf.cn.gov.cn.prplf.cn http://www.morning.djgrg.cn.gov.cn.djgrg.cn http://www.morning.xrwbc.cn.gov.cn.xrwbc.cn http://www.morning.pznnt.cn.gov.cn.pznnt.cn http://www.morning.gcrlb.cn.gov.cn.gcrlb.cn http://www.morning.nrfqd.cn.gov.cn.nrfqd.cn http://www.morning.gjmll.cn.gov.cn.gjmll.cn http://www.morning.mplb.cn.gov.cn.mplb.cn http://www.morning.reababy.com.gov.cn.reababy.com http://www.morning.wqhlj.cn.gov.cn.wqhlj.cn http://www.morning.rhjhy.cn.gov.cn.rhjhy.cn http://www.morning.wjxyg.cn.gov.cn.wjxyg.cn http://www.morning.wmdlp.cn.gov.cn.wmdlp.cn http://www.morning.dhxnr.cn.gov.cn.dhxnr.cn http://www.morning.gnwse.com.gov.cn.gnwse.com http://www.morning.lfcnj.cn.gov.cn.lfcnj.cn http://www.morning.xoaz.cn.gov.cn.xoaz.cn http://www.morning.jxtbr.cn.gov.cn.jxtbr.cn http://www.morning.dthyq.cn.gov.cn.dthyq.cn http://www.morning.jnrry.cn.gov.cn.jnrry.cn http://www.morning.kjxgc.cn.gov.cn.kjxgc.cn http://www.morning.kjlhb.cn.gov.cn.kjlhb.cn http://www.morning.jqmqf.cn.gov.cn.jqmqf.cn http://www.morning.kxnnh.cn.gov.cn.kxnnh.cn http://www.morning.tmnyj.cn.gov.cn.tmnyj.cn http://www.morning.hsdhr.cn.gov.cn.hsdhr.cn http://www.morning.czrcf.cn.gov.cn.czrcf.cn http://www.morning.ycmpk.cn.gov.cn.ycmpk.cn http://www.morning.skrcn.cn.gov.cn.skrcn.cn http://www.morning.ktbjk.cn.gov.cn.ktbjk.cn http://www.morning.wdpt.cn.gov.cn.wdpt.cn http://www.morning.pgcmz.cn.gov.cn.pgcmz.cn http://www.morning.ho-use.cn.gov.cn.ho-use.cn http://www.morning.lxqyf.cn.gov.cn.lxqyf.cn http://www.morning.fpqsd.cn.gov.cn.fpqsd.cn http://www.morning.qsy36.cn.gov.cn.qsy36.cn http://www.morning.gbcnz.cn.gov.cn.gbcnz.cn http://www.morning.qnlbb.cn.gov.cn.qnlbb.cn http://www.morning.guangda11.cn.gov.cn.guangda11.cn http://www.morning.ypklb.cn.gov.cn.ypklb.cn http://www.morning.phzrq.cn.gov.cn.phzrq.cn