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

Example 1:

Input: [1,2,3]
Output: 6

Example 2:

Input: [1,2,3,4]
Output: 24

Note:

  1. The length of the given array will be in range [3,104] and all elements are in the range [-1000, 1000].
  2. Multiplication of any three numbers in the input won't exceed the range of 32-bit signed integer.

class Solution(object):
def maximumProduct(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
n=sorted(nums)
return max(n[-1]*n[-2]*n[-3],n[0]*n[1]*n[-1])

  

[LeetCode&Python] Problem 628. Maximum Product of Three Numbers的更多相关文章

  1. 【Leetcode_easy】628. Maximum Product of Three Numbers

    problem 628. Maximum Product of Three Numbers 题意:三个数乘积的最大值: solution1: 如果全是负数,三个负数相乘还是负数,为了让负数最大,那么其 ...

  2. 628. Maximum Product of Three Numbers@python

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

  3. 【LeetCode】628. Maximum Product of Three Numbers 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:排序 日期 题目地址:https://lee ...

  4. [LeetCode] 628. Maximum Product of Three Numbers 三个数字的最大乘积

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

  5. LeetCode 628. Maximum Product of Three Numbers (最大三数乘积)

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

  6. LeetCode 628. Maximum Product of Three Numbers三个数的最大乘积 (C++)

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

  7. 628. Maximum Product of Three Numbers

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

  8. [Array]628. Maximum Product of Three Numbers

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

  9. [LeetCode&Python] Problem 104. Maximum Depth of Binary Tree

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

随机推荐

  1. 微信小程序 HMACSHA256 哈希加密

    下载CryptoJS, 增加红色的这句 module.exports = CryptoJS /* CryptoJS code.google.com/p/crypto-js (c) 2009-2012 ...

  2. List<Map<String, Object>>取值

    List<Map<String, Object>> postlist //一个list里面装着多个map,如下 [ {A=0100, B=4}, {A=0200, B=3}, ...

  3. js里面判断一个字符串是否包含某个子串的方法

    1. ES6的includes, 返回 Boolean var string = "foo", substring = "oo"; string.include ...

  4. 逆袭之旅DAY20.XIA.循环结构

    2018-07-16 19:53:47 while循环 do do...while循环 for 循环

  5. LY.猜字小游戏

    猜字小游戏

  6. 【1】windows下IOS开发基础环境搭建

    一.目的 本文的目的是windows下IOS开发基础环境搭建做了对应的介绍,大家可根据文档步骤进行mac环境部署: 二.安装虚拟机 下载虚拟机安装文件绿色版,点击如下文件安装 获取安装包:       ...

  7. java动手动脑1

    一.以下代码的输出结果是什么? int X=100; int Y=200; System.out.println("X+Y="+X+Y); System.out.println(X ...

  8. vuesheng生命周期

    对着官网的demo写例子,碰到了生命周期钩子方法,之前只是根据官网的图,了解了大概, 现在忍不住想去深扒一下,因此找了几个博客看了下,受益匪浅,故此笔记: 参考:http://www.cnblogs. ...

  9. Linux如何产看系统信息

    如何查看已安装的CentOS版本信息: 1)[root@localhost ~]# cat /proc/version Linux version 2.6.18-194.el5 (mockbuild@ ...

  10. ArrayList和LinkedList有什么区别?

    ---恢复内容开始--- ArrayList和LinkedList都实现了List接口,但是: ArrayList是基于索引的数据接口,底层是数组,能够以O(1)时间复杂度随机访问元素.而Linked ...