Without the special treatment for k >= prices.size() / 2, my code runs for 800ms, nearly Time Limited Error, so I feel there should be some better approaches.
There is actually a linear time solution for this. But that solution is too complicated and hard to code it right. If you want to know that solution, you can find it with google.
I tried to Google it a lot, but I only got O(NK) combined with O(N) quick solution for k2>=n. Can you show me the link? Thanks a lot!
please check this to see if that's what you are looking for.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.