
String
https://cplusplus.com/reference/string/string/
Upper Char to Lower
char ch = 'F';
char res = ch - 'A' + 'a'; // ASC-II value returned Lower Char to Upper
char ch = 'f';
char res = ch - 'a' + 'A';How to get the ASC-II value of any char?
char ch = '1'; // 'a', 'A'....'z'
int ascii = ch;
cout<<ascii ;Q1: Reverse String
Q1: Reverse Stringvoid 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;
}Q3: Valid Palindrome
Q3: Valid PalindromeQ5: Replace Spaces
Q5: Replace SpacesLast updated
Was this helpful?
