Ad
  • Custom User Avatar

    this requires O(n) extra space. This can be done using O(1) extra space.

  • Default User Avatar

    To me, this is a good solution, uses available STL functions and is quite readable.
    However, it could be improved by not having so much going on on the return-line. This is not a competition to write the fewest lines.
    If you want to be the envy of your coworkers in the future, write readable code.

    Also, this might be a consequence of the platform, but you should never write code in your class declaration. Always, ALWAYS put the code in the implementation.