Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Did 1 leetcode today
https://leetcode.com/problems/...
Able to run the algo on paper and wrote down the javascript, not able to pass some test cases. so need to copy the answer.
My idea is similar, but the answer is much better. The idea is similar to tracking max number, but this time we have max1, max2, max3 (max1 is largest)
init all of them to null.
looping number array, if number is in maxs, skip. If there number > max1, we update all max1-3
if number > max2, update max2-3
then number > max3, update max3
last return statement is like this: return max3 == null ? max1 : max3;
rant