leetcode 628. Maximum Product of Three Numbers | 628. 三个数的最大乘积(Java)
题目
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)相关推荐
- LeetCode 628. Maximum Product of Three Numbers
题目: Given an integer array, find three numbers whose product is maximum and output the maximum produ ...
- 628. Maximum Product of Three Numbers
- 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 ...
- C#LeetCode刷题之#628-三个数的最大乘积( Maximum Product of Three Numbers)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3726 访问. 给定一个整型数组,在数组中找出由三个数组成的最大乘 ...
- LeetCode 152. Maximum Product Subarray--动态规划--C++,Python解法
题目地址:Maximum Product Subarray - LeetCode Given an integer array nums, find the contiguous subarray w ...
- leetcode(3)——414. 第三大的数(C++中的 set,::作用符号,迭代器),628 三个数的最大乘积(sort函数的用法)
文章目录 前言 414 程序 疑惑 set ::在c++中什么意思 一.作用域符号: 二.全局作用域符号: 三.作用域分解运算符: C++ 迭代器 628 程序 疑惑 sort函数 前言 大佬的程序, ...
- 【LeetCode】Maximum Product Subarray 求连续子数组使其乘积最大
Add Date 2014-09-23 Maximum Product Subarray Find the contiguous subarray within an array (containin ...
- LeetCode 152. Maximum Product Subarray
152. Maximum Product Subarray Find the contiguous subarray within an array (containing at least one ...
- [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
最新文章
- 《用Python进行自然语言处理》第 1 章 语言处理与 Python
- 对抽象工厂+反射+配置文件的实例理解
- win10win键无反应_最新Science:强烷基CH键的无定向硼化作用
- ansys用什么cpu_ANSYS图形工作站与集群配置探讨201904-1
- 3 useReducer及其实现
- js处理富文本编辑器转义、去除转义、去除HTML标签
- 夏季学期软工综合实践小记(二)
- 四种引用类型:强、软、弱、虚
- Codeforces Round #704 (Div. 2) D - Genius‘s Gambit 思维+构造
- 用PHP实现小写金额转换大写金额【精确到分】
- do还是doing imagine加to_do还是doing imagine加to_do、to do、doing用法全汇总,再也不用担心选错啦(收藏)......
- android模拟器安装
- 跨行清算系统的实现原理
- 商超霸主之争:天猫节节败退 沦为京东陪练
- “宅米”VS“校呵呵”竞品分析报告
- 目标定位和检测系列中IOU的含义
- Altium Designer(二)——原理图(SchDoc)的绘制
- java 设计模式 路由器_java设计模式2————工厂模式
- Vim7.4 配置项列表
- 忙里偷闲又把自己的JWT实现改进了一下
热门文章
- CodeForces - 375D Tree and Queries(树上启发式合并)
- 费用流:最大费用最大流和最小费用最大流(模板)
- 中石油训练赛 - 腿部挂件(可持久化字典树)
- HDU - 1847 Good Luck in CET-4 Everybody!(sg函数,水题)
- CodeForces - 1088E Ehab and a component choosing problem(树形dp)
- 鸿蒙系统发红包,鸿蒙修真录红包版
- 约瑟夫环问题(带密码)
- Catalan数推导及应用
- Duilib教程-自动布局3-分隔条
- Ring3下Dll注入方法整理汇总