leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
2108.cpp (433B)
0 class Solution { 1 static bool isPalindrome(const string &s) { 2 int i = 0, j = size(s) - 1; 3 while (i < j) { 4 if (s[i] != s[j]) return false; 5 i++, j--; 6 } 7 return true; 8 } 9 10 public: 11 string firstPalindrome(const vector<string> &words) const { 12 for (const string &word : words) { 13 if (isPalindrome(word)) return word; 14 } 15 return ""; 16 } 17 };