Leetcode628.Maximum Product of Three Numbers三個數的最大乘積
給定一個整型陣列,在陣列中找出由三個陣列成的最大乘積,並輸出這個乘積。
示例 1:
輸入: [1,2,3] 輸出: 6
示例 2:
輸入: [1,2,3,4] 輸出: 24
注意:
- 給定的整型陣列長度範圍是[3,104],陣列中所有的元素範圍是[-1000, 1000]。
- 輸入的陣列中任意三個數的乘積不會超出32位有符號整數的範圍。
bool cmp(int x, int y) { return x > y; } class Solution { public: int maximumProduct(vector<int>& nums) { int len = nums.size(); sort(nums.begin(), nums.end(), cmp); return max(nums[0] * nums[1] * nums[2], nums[0] * nums[len - 1] * nums[len - 2]); } };
相關推薦
Leetcode628.Maximum Product of Three Numbers三個數的最大乘積
給定一個整型陣列,在陣列中找出由三個陣列成的最大乘積,並輸出這個乘積。 示例 1: 輸入: [1,2,3] 輸出: 6 示例 2: 輸入: [1,2,3,4] 輸出: 24 注意: 給定的整型陣列長度範圍是[3,104],陣列中所有的元素範圍是[-1000, 100
[LeetCode] 628. Maximum Product of Three Numbers 三個數字的最大乘積 [LeetCode] 152. Maximum Product Subarray 求最大子陣列乘積 All LeetCode Questions List 題目彙總
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
[LeetCode] 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
Leetcode628. Maximum Product of Three Numbers不要太簡單
Given an integer array, find three numbers whose product is maximum and output the maximum product.
[Swift]LeetCode628. 三個數的最大乘積 | Maximum Product of Three Numbers
pan fun UNC count nbsp fin 給定 所有 row Given an integer array, find three numbers whose product is maximum and output the maximum product.
628. Maximum Product of Three Numbers
find quest rip inpu else spa hose exce tor Given an integer array, find three numbers whose product is maximum and output the maximum
[LeetCode] Maximum Product of Three Numbers
clas style find leet 數組元素 cat 兩個 bit bsp Given an integer array, find three numbers whose product is maximum and output the maximum produ
[Array]628. Maximum Product of Three Numbers
最大 return array 最大值 who element begin ray bsp Given an integer array, find three numbers whose product is maximum and output the maximum
[Leetcode]628. Maximum Product of Three Numbers
hose maximum cnblogs rip max etc 就是 find not Given an integer array, find three numbers whose product is maximum and output the maxim
leetcode-628-Maximum Product of Three Numbers
ssi arr spa tip iss beat nth col 就是 題目描述: Given an integer array, find three numbers whose product is maximum and output the maximum prod
628. Maximum Product of Three Numbers@python
output product eas tps com maximum tar blank find Given an integer array, find three numbers whose product is maximum and output the maxi
628.Maximum Product Of Three Numbers
Given an integer array, find three numbers whose product is maximum and output the maximum product. Note: The length of the given array
leetcode (Maximum Product of Three Numbers)
Title:Maximum Product of Three Numbers 605 Difficulty:Easy 原題leetcode地址:https://leetcode.com/problems/can-place-flowers/
[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 &n
【python3】leetcode 628. Maximum Product of Three Numbers(easy)
628. Maximum Product of Three Numbers(easy) 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. Example 1: Input: [1,2,3] O
【Leetcode】628. 三個數最大乘積
題目描述: 給定一個整型陣列,在陣列中找出由三個陣列成的最大乘積,並輸出這個乘積。 示例 1: 輸入: [1,2,3] 輸出: 6 示例 2: 輸入: [1,2,3,4] 輸出: 24 注意: 給定的整型陣列長度範圍是[3,104],陣列中所有的元素範圍是[
646. Maximum Length of Pair Chain 對鏈最大長度
fin eve select solution www elf stc amp ati You are given n pairs of numbers. In every pair, the first number is always smaller than the
(C語言)用函式實現求三個數最大值
題目描述:從鍵盤輸入三個數,之後呼叫函式實現求三個數的最大值 程式碼實現: #include<stdio.h> int main() { int qmax(int a,int b,int c); //求最大值函式的宣告 int x,y,z; int max
三個數最大值(if)
輸入三個數,輸出最大值; #include<stdio.h> int main() { int a,b,c,max; scanf("%d%d%d",&a,&