[LeetCode&Python] Problem 628. Maximum Product of Three Numbers
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:
- The length of the given array will be in range [3,104] and all elements are in the range [-1000, 1000].
- 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的更多相关文章
- 【Leetcode_easy】628. Maximum Product of Three Numbers
problem 628. Maximum Product of Three Numbers 题意:三个数乘积的最大值: solution1: 如果全是负数,三个负数相乘还是负数,为了让负数最大,那么其 ...
- 628. Maximum Product of Three Numbers@python
Given an integer array, find three numbers whose product is maximum and output the maximum product. ...
- 【LeetCode】628. Maximum Product of Three Numbers 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:排序 日期 题目地址:https://lee ...
- [LeetCode] 628. Maximum Product of Three Numbers 三个数字的最大乘积
Given an integer array, find three numbers whose product is maximum and output the maximum product. ...
- LeetCode 628. Maximum Product of Three Numbers (最大三数乘积)
Given an integer array, find three numbers whose product is maximum and output the maximum product. ...
- LeetCode 628. Maximum Product of Three Numbers三个数的最大乘积 (C++)
题目: Given an integer array, find three numbers whose product is maximum and output the maximum produ ...
- 628. Maximum Product of Three Numbers
Given an integer array, find three numbers whose product is maximum and output the maximum product. ...
- [Array]628. Maximum Product of Three Numbers
Given an integer array, find three numbers whose product is maximum and output the maximum product. ...
- [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 ...
随机推荐
- [LeetCode] 99. Recover Binary Search Tree(复原BST) ☆☆☆☆☆
Recover Binary Search Tree leetcode java https://leetcode.com/problems/recover-binary-search-tree/di ...
- mfscli的使用方法(解决mfscgi响应慢的问题)
在moosefs中,mfscgi是一个python写的server程序,其中的数据是调用同样的python工具mfscli实现的. 每当用浏览器打开mfscgi的时候,它要把所有的表数据请求一遍,非常 ...
- Net Core2.0 升级到.Net Core 2.1
1. 安装新 .Net Core SDK 2.1 2. 升级VS.net 到15.7, 这个版本极其不好用,IIS打中文会自动退出,但现在也没办法降级了.只能等微软打补丁. 3. 对于面向 ASP.N ...
- 转: Linux mount/unmount命令
https://blog.csdn.net/okhymok/article/details/76616892 楼主具体哪里转的 我不清楚 好像没看到原始出处 开机自动挂载 如果我们想实现开机自动挂载某 ...
- window.open()打开页面
一.window.open()支持环境:JavaScript1.0+/JScript1.0+/Nav2+/IE3+/Opera3+ 二.基本语法:window.open(pageURL,name,pa ...
- (C/C++学习笔记) 二. 数据类型
二. 数据类型 ● 数据类型和sizeof关键字(也是一个操作符) ※ 在现代半导体存储器中, 例如在随机存取存储器或闪存中, 位(bit)的两个值可以由存储电容器的两个层级的电荷表示(In mode ...
- :适配器模式:Adapter
#ifndef __ADAPTER_H__ #define __ADAPTER_H__ #include <iostream> using namespace std; class Duc ...
- FIFO的使用总结
使用FIFO积累 FIFO是在FPGA设计中使用的非常频繁,也是影响FPGA设计代码稳定性以及效率等得关键因素.我总结一下我在使用FIFO过程中的一些心得,与大家分享. 我本人是做有线 ...
- OJ_查找二叉树
#include<iostream>using namespace std;int n,m;int d[120];int t=1;int re;struct Node{ int data; ...
- Problem B 一元二次方程类
Description 定义一个表示一元二次方程的类Equation,该类至少具有以下3个数据成员:a.b和c,用于表示方程“a*x*x + b*x +c = 0”.同时,该类还至少具有以下两个成员函 ...