Skip to content

Commit bf0a87e

Browse files
authored
Merge pull request #3301 from benmak11/2108-first-palindrome
Create 2108-find-first-palindromic-string-in-the-array.java
2 parents f688941 + 42e147f commit bf0a87e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
public class Solution {
2+
3+
public String firstPalindrome(String[] words) {
4+
for (int i = 0; i < words.length; i++) {
5+
String word = words[i];
6+
int x = 0, y = word.length() - 1;
7+
while (word.charAt(x) == word.charAt(y)) {
8+
if (x >= y)
9+
return word;
10+
else {
11+
x++;
12+
y--;
13+
}
14+
}
15+
}
16+
return "";
17+
}
18+
19+
}

0 commit comments

Comments
 (0)