使用归并排序和快速排序:时间复杂度为O(nlogn),快排132ms,归并880ms,stl 的sort() 80ms
考虑到负数,最大值有两种情况:两个负数一个正数相乘,或者三个正数相乘,取两个的最大值
class Solution {public: int findpivot(vector &nums,int start,int end){ int pivot=nums[start]; int i=start,j=end; while(i=pivot) j--; nums[i]=nums[j]; while(i <=pivot) i++; nums[j]=nums[i]; } nums[i]=pivot; return i; } void quicksort(vector &nums,int start,int end){ if(start>=end) return; int pivotkey=findpivot(nums,start,end); quicksort(nums,start,pivotkey-1); quicksort(nums,pivotkey+1,end); } void merge(vector &nums,int start,int mid,int end){ vector tmp; int i=start,j=mid+1; while(i<=mid&&j<=end){ if(nums[i]