[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 ...
随机推荐
- unity中让物体移动到鼠标点击地面任一点的位置(单击移动和双击暂停移动)并生成图标
using UnityEngine; using System.Collections.Generic; using UnityEngine.EventSystems; using UnityEngi ...
- Python3 线程/进程池 concurrent.futures
python3之concurrent.futures一个多线程多进程的直接对接模块,python3.2有线程池了 Python标准库为我们提供了threading和multiprocessing模块编 ...
- set循环遍历删除特定元素
使用Iterator迭代器 public class Demo { public static void main(String[] args) { Set<Object> obj = n ...
- 四:(之一和之二) docker架构和底层技术分析(C/S架构)
1.架构和底层技术 Docker Host提供了RESTUL api,使docker client可以通过这些命令调用dockerd. Registry是一个公用的存储镜像的容器,类似于github. ...
- CSS学习笔记-03- 过渡模块之前奏篇 a标签的伪类选择器
CSS3 2D转换CSS3 3D转换CSS3 过渡CSS3 动画 CSS3 的四大金刚. 想要实现酷炫的视觉效果,上面4个是必须要掌握的.学习之前,先复习一下 视觉盛宴的前菜 :a标签的伪类选择器 铛 ...
- Vim 文件配置
cat ~/.vimrc syntax on set nu set encoding=utf-8 set ts=4 set fileencodings=ucs-bom,utf-8,cp936 set ...
- synchronized 和 ReentrantLock 区别
synchronized 使用: 1:当一个线程访问object的一个synchronized(this)同步代码块时,它就获得了这个object的对象锁.结果,其它线程对该object对象所有同步代 ...
- vs2017 乱码
vs2017默认编码方式并不是UTF-8,似乎是UTF-16,当我们使用中文时,经常会发生乱码. 解决方法:工具->扩展和更新->联机,然后搜索ForceUTF8 我这里已经安装了,没安装 ...
- centos7安装kvm
一. 安装kvm前的准备工作 1. 清除iptables规则 service iptables save service iptables stop 2. 关闭selinux sed -i 's/SE ...
- Linux:http配置
http配置 1.挂载系统:mount /dev/cdrom /mnt/cdrom2.安装:rpm -ivh httpd-2.4.6-88.el7.centos.x86_64.rpm2.启动服务:sy ...