hi, let Avik connect you.


** You can give your thought about this content and request modifications if needed from Ask For Modifications page. Thank You.

** You can check all the posts on the Posts page.

** More about me in the About Me section.

Reverse String


  • Approach:

    1. For each character in a string, starting from 0 to N/2 (where N = length of the given string), swap ith character with (n-i)th character.


  • Time and Space Complexity:

      • Time Complexity: O(N)

      • Space Complexity: O(1)


Code [C++]

class Solution {

public:

void reverseString(vector<char>& s) {

int n = s.size();

for(int i=0; i<n/2; i++){

swap(s[i], s[n-i-1]);

}

}

};