forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_2108.java
More file actions
28 lines (26 loc) · 726 Bytes
/
_2108.java
File metadata and controls
28 lines (26 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.fishercoder.solutions;
public class _2108 {
public static class Solution1 {
public String firstPalindrome(String[] words) {
for (String word : words) {
if (isPal(word)) {
return word;
}
}
return "";
}
private boolean isPal(String word) {
int left = 0;
int right = word.length() - 1;
while (left < right) {
if (word.charAt(left) != word.charAt(right)) {
return false;
} else {
left++;
right--;
}
}
return true;
}
}
}