344 Reverse String Use two pointers i, j. keep switching elements at position i, j while i < j. string reverseString(string s) { for (int i = 0, j = s.size() - 1; i < j; i++, j--) swap(s[i], s[j]); return s; } 345 Reverse Vowels of a String Similar with 344 Reverse String , except we need to guard the swap operation conditionally based on whether the current two chars are vowels or not. 283 Move Zeroes Use two pointers, the front iterates the elements in the array. while the tail one keeps the current store position. If front is not zero, store it to the tail position and increase tail pointer. After the loop, set all the remaining with zero. 349 Intersection of Two Arrays ...
Comments
Post a Comment