Advertisement
mantha_raghava

Find First Palindromic String in the Array

Feb 13th, 2024
638
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | Source Code | 0 0
  1. class Solution {
  2.     public boolean checkPalindrome(String s){
  3.         int p1=0, p2=s.length()-1;
  4.         while(p1<p2){
  5.             if(s.charAt(p1)!=s.charAt(p2)){
  6.                 return false;
  7.             }
  8.             p1++;
  9.             p2--;
  10.         }
  11.         return true;
  12.     }
  13.     public String firstPalindrome(String[] words) {
  14.         for(String i:words){
  15.             boolean flag = checkPalindrome(i);
  16.             if(flag){
  17.                 return i;
  18.             }
  19.         }
  20.         return "";        
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement