[codility]Max-product-of-three
来源:互联网 发布:tensorflow 图片分类 编辑:程序博客网 时间:2024/05/22 20:20
// you can also use includes, for example:#include <algorithm>#include <climits>int solution(vector<int> &A) { // write your code in C++98 //...sort A first sort(A.begin(), A.end()); //...enumerate Q, and then divide to 4 cases, keep record of globalMax int globalMax = INT_MIN; int n = A.size(); for(int Q = 1; Q < n-1; ++Q) { int localMax; if(A[Q] > 0) { if(A[Q-1] < 0) localMax = A[Q-1]*A[Q]*A[Q+1]; else if(A[Q-1] == 0) localMax = 0; else localMax = A[Q-1]*A[Q]*A[n-1]; } else if(A[Q] == 0) localMax = 0; else//A[Q] < 0 { if(A[n-1] < 0) localMax = A[Q-1]*A[Q]*A[n-1]; else if(A[n-1] == 0) localMax = 0; else localMax = A[0]*A[Q]*A[n-1]; } globalMax = max(globalMax, localMax); } //...return result return globalMax;}
- [codility]Max-product-of-three
- Maximum Product of Three Numbers
- Maximum Product of Three Numbers
- Maximum Product of Three Numbers
- leetcode628. Maximum Product of Three Numbers
- leetcode 628:Maximum Product of Three Numbers
- [leetcode]628. Maximum Product of Three Numbers
- Leetcode 628 Maximum Product of Three Numbers
- leetcode#628. Maximum Product of Three Numbers
- 628. Maximum Product of Three Numbers
- 628. Maximum Product of Three Numbers
- leetcode628: Maximum Product of Three Numbers
- leetcode: 628. Maximum Product of Three Numbers
- leetcode-- Maximmum Product of Three Numbers
- leetcode 628. Maximum Product of Three Numbers
- LeetCode628 : Maximum Product of Three Numbers
- 628. Maximum Product of Three Numbers
- [LeetCode] 628. Maximum Product of Three Numbers
- 【数组】14周项目三。成绩处理
- [codility]Genomic-range-query
- 开始写博客,看自己能坚持多久
- [codility]Triangle
- python 字符编码
- [codility]Max-product-of-three
- [codility]Number-of-disc-intersections
- hibernate中联合主键的生成策略
- C++必知必会之(24)成员函数查找
- 顺手的Linux发行版及其工具推荐
- [codility]Brackets
- Rooyee Messenger 2.3.1 源码调试报接口不支持异常的解决办法
- cocos2d-x 对传入的字符串进行解析分割 解析
- python MySQLdb手动简单操作源码