• Skip to primary navigation
  • Skip to content
  • Skip to footer
zhicheng xie's demo blog
  • Quick-Start Guide

    Your Name

    I am an amazing person.

    • Somewhere

    Find First Palindromic String in the Array

    less than 1 minute read

    <-E 2108> Find First Palindromic String in the Array

    class Solution {
    public:
        string firstPalindrome(vector<string>& words) {
            for(auto word : words){
                int p1 = 0;
                int p2 = word.size() - 1;
                string a = word;
                while(p1 < p2){
                    if(a[p1] !=a [p2]) {
                        break;
                    }
                    p1++;
                    p2--;
                }
                if((p1 == p2) || ((p1 - p2)==1))
                    return a;
            }
            return "";
        }
    };
    

    Tags: Algorithms, C++, Leetcode

    Updated: April 16, 2022

    Share on

    Twitter Facebook LinkedIn
    Previous Next

    You may also enjoy

    Decode Ways

    less than 1 minute read

    <-M 91> Decode Ways

    Word Break

    less than 1 minute read

    <-H 139> Word Break

    Distinct Subsequences

    less than 1 minute read

    <-H 115> Distinct Subsequences

    Edit Distance

    less than 1 minute read

    <-H 72> Edit Distance

    • Follow:
    • Feed
    © 2023 zhicheng xie's blog. Powered by Jekyll & Minimal Mistakes.