1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | ,错误原因:Line 9: execution reached the end of a value-returning function without returning a value class Solution { public : int findKthLargest(vector< int >& nums, int k) { return quickSort(nums , 0 , nums.size()-1 ,nums.size() - k); } int quickSort(vector< int >& nums , int l , int r , int t ){ int p = partition(nums ,l ,r ); if (t == p) return nums[p]; else if (t < p) quickSort(nums , l ,p-1 , t); else quickSort(nums, p+1 , r ,t); } int partition(vector< int >& nums , int l , int r){ int v = nums[l]; int i = l+1,j = l; //[l+1,j]保存<v的元素 for (; i <= r; i++) if (nums[i] < v) swap(nums[i],nums[++j]); swap(nums[l], nums[j]); return j; } }; |