Skip to content

Commit b3e4761

Browse files
authored
Create 5956-find-first-palindromic-string-in-the-array.js
1 parent 2525861 commit b3e4761

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @param {string[]} words
3+
* @return {string}
4+
*/
5+
const firstPalindrome = function(words) {
6+
for(let str of words) {
7+
if(isPa(str)) return str
8+
}
9+
10+
return ''
11+
};
12+
13+
function isPa(str) {
14+
let l = 0, r = str.length - 1
15+
while(l < r) {
16+
if(str[l] !== str[r]) return false
17+
l++
18+
r--
19+
}
20+
21+
22+
return true
23+
}

0 commit comments

Comments
 (0)