题目

https://leetcode-cn.com/problems/maximum-product-of-three-numbers/

题解

找到三个数的最大乘积。先给数组排序,考虑可能有负数的情况,最大的乘积只有两种组合方式:

class Solution {public int maximumProduct(int[] nums) {Arrays.sort(nums);int len = nums.length;int n1 = nums[0] * nums[1] * nums[len - 1];int n2 = nums[len - 1] * nums[len - 2] * nums[len - 3];return Math.max(n1, n2);}
}

leetcode 628. Maximum Product of Three Numbers | 628. 三个数的最大乘积(Java)相关推荐

  1. LeetCode 628. Maximum Product of Three Numbers

    题目: Given an integer array, find three numbers whose product is maximum and output the maximum produ ...

  2. 628. Maximum Product of Three Numbers

  3. LeetCode 421. Maximum XOR of Two Numbers in an Array--Python解法

    LeetCode 421. Maximum XOR of Two Numbers in an Array–C++,Python解法 LeetCode题解专栏:LeetCode题解 我做的所有的Leet ...

  4. C#LeetCode刷题之#628-三个数的最大乘积( Maximum Product of Three Numbers)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3726 访问. 给定一个整型数组,在数组中找出由三个数组成的最大乘 ...

  5. LeetCode 152. Maximum Product Subarray--动态规划--C++,Python解法

    题目地址:Maximum Product Subarray - LeetCode Given an integer array nums, find the contiguous subarray w ...

  6. leetcode(3)——414. 第三大的数(C++中的 set,::作用符号,迭代器),628 三个数的最大乘积(sort函数的用法)

    文章目录 前言 414 程序 疑惑 set ::在c++中什么意思 一.作用域符号: 二.全局作用域符号: 三.作用域分解运算符: C++ 迭代器 628 程序 疑惑 sort函数 前言 大佬的程序, ...

  7. 【LeetCode】Maximum Product Subarray 求连续子数组使其乘积最大

    Add Date 2014-09-23 Maximum Product Subarray Find the contiguous subarray within an array (containin ...

  8. LeetCode 152. Maximum Product Subarray

    152. Maximum Product Subarray Find the contiguous subarray within an array (containing at least one ...

  9. [leetcode]421. Maximum XOR of Two Numbers in an Array

    421. Maximum XOR of Two Numbers in an Array Given a non-empty array of numbers, a0, a1, a2, - , a

最新文章

  1. 《用Python进行自然语言处理》第 1 章 语言处理与 Python
  2. 对抽象工厂+反射+配置文件的实例理解
  3. win10win键无反应_最新Science:强烷基CH键的无定向硼化作用
  4. ansys用什么cpu_ANSYS图形工作站与集群配置探讨201904-1
  5. 3 useReducer及其实现
  6. js处理富文本编辑器转义、去除转义、去除HTML标签
  7. 夏季学期软工综合实践小记(二)
  8. 四种引用类型:强、软、弱、虚
  9. Codeforces Round #704 (Div. 2) D - Genius‘s Gambit 思维+构造
  10. 用PHP实现小写金额转换大写金额【精确到分】
  11. do还是doing imagine加to_do还是doing imagine加to_do、to do、doing用法全汇总,再也不用担心选错啦(收藏)......
  12. android模拟器安装
  13. 跨行清算系统的实现原理
  14. 商超霸主之争:天猫节节败退 沦为京东陪练
  15. “宅米”VS“校呵呵”竞品分析报告
  16. 目标定位和检测系列中IOU的含义
  17. Altium Designer(二)——原理图(SchDoc)的绘制
  18. java 设计模式 路由器_java设计模式2————工厂模式
  19. Vim7.4 配置项列表
  20. 忙里偷闲又把自己的JWT实现改进了一下

热门文章

  1. CodeForces - 375D Tree and Queries(树上启发式合并)
  2. 费用流:最大费用最大流和最小费用最大流(模板)
  3. 中石油训练赛 - 腿部挂件(可持久化字典树)
  4. HDU - 1847 Good Luck in CET-4 Everybody!(sg函数,水题)
  5. CodeForces - 1088E Ehab and a component choosing problem(树形dp)
  6. 鸿蒙系统发红包,鸿蒙修真录红包版
  7. 约瑟夫环问题(带密码)
  8. Catalan数推导及应用
  9. Duilib教程-自动布局3-分隔条
  10. Ring3下Dll注入方法整理汇总