leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2108.cpp (433B)


      1 class Solution {
      2     static bool isPalindrome(const string &s) {
      3         int i = 0, j = size(s) - 1;
      4         while (i < j) {
      5             if (s[i] != s[j]) return false;
      6             i++, j--;
      7         }
      8         return true;
      9     }
     10 
     11   public:
     12     string firstPalindrome(const vector<string> &words) const {
     13         for (const string &word : words) {
     14             if (isPalindrome(word)) return word;
     15         }
     16         return "";
     17     }
     18 };