leetcode-solutions
leetcode-solutions copied to clipboard
Added-cpp-solution
I know this passes the test. but why this works? seems the complexity is n * n?
Yes it runs at n^2. I uploaded it as it will be easy to understand for beginners. I can also add the solution that has linear time complexity.
I updated the code. You may check.
Thanks
this works as well -- except that the run time complexity is bigger than
"Your algorithm should run in O(n) time and uses constant extra space."
this implies modifications of the input array IMO. without this constraint, this problem would be easy
Ok.. I accept. Now you can check. I've updated the solution that runs in linear time and with constant space.
it is actually still not o n since u r using sort