O(n) time + O(1) space.
----------------解决方案--------------------------------------------------------
以下是引用HJin在2007-9-16 13:03:19的发言:
I think the algorithm for solving the invesion prolbem is O(n^2) --- you have two for loops and I would think in the worst case scenario, you will have O(n^2).
I submitted a O(n lgn) algorithm at yzfy.org, which uses a STL set (the set brings me TLE always).
I think the algorithm for solving the invesion prolbem is O(n^2) --- you have two for loops and I would think in the worst case scenario, you will have O(n^2).
I submitted a O(n lgn) algorithm at yzfy.org, which uses a STL set (the set brings me TLE always).
Where are you come from?
----------------解决方案--------------------------------------------------------
china ! i think
----------------解决方案--------------------------------------------------------