--- title: "找出数组中的第一个回文字符串" created: 2025-11-28 tags: - 算法 --- # 找出数组中的第一个回文字符串 ## 题目 [找出数组中的第一个回文字符串](https://leetcode.com/problems/find-first-palindromic-string-in-the-array/description/) ![[image-50d8dfc4.png]] ## 思路分析 本来想用异或做 如果是回文串的话 相同的数抵消 若偶数长 最后得0 若奇数长 最后得剩余的那个数 与中间数比较相等 但是有可能存在巧合 一堆不同的数异或后得到的结果 正好等于中间的数…… 所以这样不行 ![[image-52ea3635.png]] 代码写了蛮久的 别浪费了 贴在这 ```java class Solution { public: bool check(string &word){ int l=0,r=word.size()-1; while(l& words) { for(auto word:words){ if(check(word)) return word; } return ""; } }; ``` 那老老实实做吧 左右指针中间逼近 若发现有一位不等就判否 下一个 ## 代码实现 ```java class Solution { public: bool check(string &word){ int l=0,r=word.size()-1; while(l& words) { for(auto word:words){ if(check(word)) return word; } return ""; } }; ``` ## 同类题型 ## 视频讲解 --- ⬅️ [[对撞指针|对撞指针]] 🏠 [[00-刷题理模型]] ➡️ [[2-Learning/02-算法/03-刷题理模型/双指针相关模型/对撞指针/接雨水|接雨水]]