Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4dfdc70

Browse files
add 2108
1 parent b3bcc5b commit 4dfdc70

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|2108|[Find First Palindromic String in the Array](https://leetcode.com/problems/find-first-palindromic-string-in-the-array/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2108.java) ||Easy||
1112
|2103|[Rings and Rods](https://leetcode.com/problems/rings-and-rods/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2103.java) ||Easy||
1213
|2099|[Find Subsequence of Length K With the Largest Sum](https://leetcode.com/problems/find-subsequence-of-length-k-with-the-largest-sum/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2099.java) ||Easy||
1314
|2095|[Delete the Middle Node of a Linked List](https://leetcode.com/problems/delete-the-middle-node-of-a-linked-list/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2095.java) ||Medium||
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _2108 {
4+
public static class Solution1 {
5+
public String firstPalindrome(String[] words) {
6+
for (String word : words) {
7+
if (isPal(word)) {
8+
return word;
9+
}
10+
}
11+
return "";
12+
}
13+
14+
private boolean isPal(String word) {
15+
int left = 0;
16+
int right = word.length() - 1;
17+
while (left < right) {
18+
if (word.charAt(left) != word.charAt(right)) {
19+
return false;
20+
} else {
21+
left++;
22+
right--;
23+
}
24+
}
25+
return true;
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)