-
Notifications
You must be signed in to change notification settings - Fork 0
2108_FindFirstPalindromicStringintheArray
a920604a edited this page Apr 14, 2023
·
1 revision
class Solution {
public:
bool isPalindrome(string s){
int l = 0, r = s.size()-1;
while(l<r){
if(s[l++] !=s[r--]) return false;
}
return true;
}
string firstPalindrome(vector<string>& words) {
for(string word:words){
if(isPalindrome(word)) return word;
}
return "";
}
};
- time complexity
O(n)
- space complexity
O(1)
footer