Skip to content

Commit 2149073

Browse files
authored
Update Find First Palindromic String in the Array.java
1 parent 35f0022 commit 2149073

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
class Solution {
2-
public String firstPalindrome(String[] words) {
3-
return Arrays.stream(words).filter(Solution::isPalindrome).findFirst().orElse("");
4-
}
5-
6-
public static boolean isPalindrome(String s) {
7-
return new StringBuilder().append(s).reverse().toString().equals(s);
8-
}
2+
public String firstPalindrome(String[] words) {
3+
return Arrays.stream(words)
4+
.filter(word -> word.equals(new StringBuilder(word).reverse().toString()))
5+
.findFirst()
6+
.orElse("");
7+
}
98
}

0 commit comments

Comments
 (0)