这道题十分不容易啊,做到半夜。

class Solution {
public:
static int cmp628(int a, int b)
{
return a > b;
} static int cmp628_2(int a, int b)
{
return abs(a) < abs(b);
} int maximumProduct(vector<int>& nums) {
const int N = ;
int Pos[N];
int Nag[N];
int Nor[N]; int i = , j = , k = ;
for (auto n : nums)
{
if (n >= )
{
Pos[i] = n;
i++;
}
else
{
Nag[j] = n;
j++;
}
Nor[k] = n;
k++;
} sort(Pos, Pos + i, cmp628);
sort(Nag, Nag + j);
sort(Nor, Nor + k, cmp628_2); int a = INT_MIN, b = INT_MIN, c = INT_MIN, d = INT_MIN, max = INT_MIN; //三正
if (i >= )
{
a = Pos[] * Pos[] * Pos[];
if (j >= )
{
b = Pos[] * Nag[] * Nag[];
}
}
else if (i >= )
{
a = Pos[] * Pos[] * Nag[];
if (j >= )
{
b = Pos[] * Nag[] * Nag[];
}
}
if (j >= )
{
c = Nag[] * Nag[] * Nag[];
if (i >= )
{
d = Nag[j - ] * Pos[] * Pos[];
}
else if (i == )
{
d = Nag[] * Nag[] * Pos[];
} }
else if (j >= )
{
c = Nag[] * Nag[] * Pos[];
if (i >= )
{
d = Nag[j - ] * Pos[] * Pos[];
}
else if (i == )
{
d = Nag[] * Nag[] * Pos[];
}
} if (max < a)
max = a;
if (max < b)
max = b;
if (max < c)
max = c;
if (max < d)
max = d; return max;
}
};

leetcode628的更多相关文章

  1. [Swift]LeetCode628. 三个数的最大乘积 | Maximum Product of Three Numbers

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

  2. Leetcode628.Maximum Product of Three Numbers三个数的最大乘积

    给定一个整型数组,在数组中找出由三个数组成的最大乘积,并输出这个乘积. 示例 1: 输入: [1,2,3] 输出: 6 示例 2: 输入: [1,2,3,4] 输出: 24 注意: 给定的整型数组长度 ...

随机推荐

  1. Pycharm更换pip源为国内

    Python里的pip是官方自带的源,国内使用pip安装的时候十分缓慢,所以最好是更换成中国国内的源地址. 目前国内靠谱的 pip 镜像源有: 清华: https://pypi.tuna.tsingh ...

  2. C++两种字符串传参构造函数

    第一种: #include"iostream" #include"string" using namespace std; class Motor{ prote ...

  3. .net如何解析二维码图片

    二维码现在越来越流行,可以使用手机上或其它移动终端上的二维码扫描器软件对着二维码一扫,就可以得到相关信息.在互联网站上,可以找到很多二维码的工具,甚至还有不少在线生成.解析二维码的网站.在业务系统当中 ...

  4. Spring Boot入门——使用jsp

    使用步骤: 1.创建Maven web project项目 2.在pom.xml文件中添加依赖 <project xmlns="http://maven.apache.org/POM/ ...

  5. Oracle删除步骤

    1.Oracle卸载要求比较严格,不能简单的卸载就完事了:当然Oracle卸载也没有那么难,只是步骤比较多.Oracle10g还是Oracle11g卸载步骤都是一样的.下边详细介绍一下. 找到Orac ...

  6. 使用GridSearchCV寻找最佳参数组合——机器学习工具箱代码

    # -*- coding: utf-8 -*- import numpy as np from sklearn.feature_extraction import FeatureHasher from ...

  7. cassandra mongodb选择——cassandra:分布式扩展好,写性能强,以及可以预料的查询;mongodb:非事务,支持复杂查询,但是不适合报表

    Of course, like any technology MongoDB has its strengths and weaknesses. MongoDB is designed for OLT ...

  8. 20 Python 常用模块

    collections模块 在内置数据类型(dict.list.set.tuple)的基础上,collections模块还提供了几个额外的数据类型:Counter.deque.defaultdict. ...

  9. ps6-工具的基础使用

    1.图像的移动与对齐 ctrl+j:复制图层,然后再移动不损坏原来的图像. Ctrl+Z =返回键 Shift+单击最下方图层 选择全部 Alt+鼠标移动 复制并粘贴 2.规则选择工具组 shift键 ...

  10. luogu 3375 KMP模板题

    #include<bits/stdc++.h> using namespace std; ,M = ; int next[N]; void getNext(char s[]) //找nex ...