Reverse String | LeetCode 344

AFFILIATE LINKS

Great resource I use to learn algorithms.
40% off Tech Interview Pro: http://techinterviewpro.com/terriblewhiteboard
20% off CoderPro: http://coderpro.com/terriblewhiteboard


Here is the full implementation.

/*
  The key is to use two pointers, one for the beginning, and
  one for the end. Switch the letters while start > end
*/
let reverseString = function(s) {
  let start = 0;
  let end = s.length - 1;
  
/* this loop references two letters at the same time. it starts with the first
and last letters and moves inward */
  while (start < end) {
    let tempFirst = s[start];
    s[start] = s[end];
    s[end] = tempFirst;
    start++;
    end--;
  }
}