Skip to content

Commit

Permalink
Q2108 added.
Browse files Browse the repository at this point in the history
  • Loading branch information
isinsuarici committed Mar 5, 2023
1 parent b91f782 commit cb51a42
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions E_2108_FindFirstPalindromicStringIntheArray.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
public String firstPalindrome(String[] words) {
for (String el: words){
int left=0;
int right= el.length()-1;
int len=el.length();
if(len==1)
return el;
while(left<right){
if(el.charAt(left++)!=el.charAt(right--)){
break;
}
if(left==right && len%2==1)
return el;
else if(left-right==1 && len%2==0)
return el;
}
}
return "";
}
}

0 comments on commit cb51a42

Please sign in to comment.