https://leetcode.com/problems/maximum-number-of-coins-you-can-get/description/?envType=daily-question&envId=2023-11-24
I solve this problem by sorting piles first, and choose piles for(let i=1;i<(piles.length/3)*2;i+=2)
but:
o(≧口≦)o
Problem must lies in sort, nlogn is too slow
Notice that piles[i]
's range is surprisingly small, we can declare an int A[10000]
without any mental burden
so why just try bucket sort (bucket size==1), and the Time Complexity can reach astonishing O(n)!
We dont even have to assemble the elements to be an array, and we just use the bucket, scan from the no.10000 to no.0, to solve this problem