LeetCode #344

Write a function that takes a string as input and returns the string reversed.


Given s = “hello”, return “olleh”.

Pseudo code

  1. Convert string to array of letters
  2. The goal is to swap each letter with it’s opposite one.
  3. Half of the length is the times we need to swap. If it’s an odd length array, then round to the smaller side.
  4. Use a while loop to swap letters
  5. Join the reversed array back into a string and return


See the Pen 344. Reverse String by Cherry Wang (@chryw) on CodePen.