2108. Find First Palindromic String in the Array 發表於 2023-02-13 | 分類於 leetcode problemsolution1234567891011121314151617class 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 ""; }}; analysis time complexity O(n) space complexity O(1)