Page cover

String

https://cplusplus.com/reference/string/string/

void reverseString(vector<char>& s) {
        reverse(s.begin(), s.end());
}

It reverses the order of the elements in the range [first, last) of any container. The time complexity of this function is O(n), and the space complexity of this program is also O(1).

bool isPalindrome(int x) {
    string s = to_string(x);
    string temp = to_string(x);

    reverse(s.begin(), s.end());
    if(s == temp)
         return true;
    else
         return false;
}

Dry Run

Last updated

Was this helpful?