Find First Palindromic String in the Array LeetCode solution in C++

1
class Solution {
2
bool isPalindrome(string str) {
3
int i = 0;
4
int j = str.length() - 1;
5
while (i <= j) {
6
if (str[i] != str[j]) return false;
7
i++;
8
j--;
9
}
10
return true;
11
}
12

13
public:
14
string firstPalindrome(vector<string> &words) {
15
for (int i = 0; i < words.size(); i++) {
16
if (isPalindrome(words[i])) return words[i];
17
}
18
return "";
19
}
20
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0