Skip to content

Instantly share code, notes, and snippets.

@sedmo
Created August 3, 2020 18:22
Show Gist options
  • Save sedmo/b4416d7efbe7963da1ac12a0b2a0bf44 to your computer and use it in GitHub Desktop.
Save sedmo/b4416d7efbe7963da1ac12a0b2a0bf44 to your computer and use it in GitHub Desktop.
Week Day 3 August 2020 leetcode challenge
class Solution {
void printArray(vector<char> arr){
cout<<"[";
for(auto c: arr){
cout<<c<<",";
}
cout<<"]"<<endl;
}
vector<char> stringToArrLower(string s){
vector<char> arr;
for(auto ch: s){
if(isalnum(ch)){
char next = isalpha(ch) ? tolower(ch) : ch;
arr.push_back(next);
}
}
return arr;
}
public:
//runtime : O(1) | space: O(n)
bool isPalindrome(string s) {
vector<char> arr;
arr = stringToArrLower(s);
int l = 0;
int r = arr.size()-1;
while(l<r){
if(arr.at(l) != arr.at(r)){
return false;
}
l++;
r--;
}
return true;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment