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

Commit 5b2bf97

Browse files
committed
Add solution #2108
1 parent 81be90b commit 5b2bf97

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,751 LeetCode solutions in JavaScript
1+
# 1,752 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1614,6 +1614,7 @@
16141614
2104|[Sum of Subarray Ranges](./solutions/2104-sum-of-subarray-ranges.js)|Medium|
16151615
2105|[Watering Plants II](./solutions/2105-watering-plants-ii.js)|Medium|
16161616
2106|[Maximum Fruits Harvested After at Most K Steps](./solutions/2106-maximum-fruits-harvested-after-at-most-k-steps.js)|Hard|
1617+
2108|[Find First Palindromic String in the Array](./solutions/2108-find-first-palindromic-string-in-the-array.js)|Easy|
16171618
2114|[Maximum Number of Words Found in Sentences](./solutions/2114-maximum-number-of-words-found-in-sentences.js)|Easy|
16181619
2115|[Find All Possible Recipes from Given Supplies](./solutions/2115-find-all-possible-recipes-from-given-supplies.js)|Medium|
16191620
2116|[Check if a Parentheses String Can Be Valid](./solutions/2116-check-if-a-parentheses-string-can-be-valid.js)|Medium|
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* 2108. Find First Palindromic String in the Array
3+
* https://leetcode.com/problems/find-first-palindromic-string-in-the-array/
4+
* Difficulty: Easy
5+
*
6+
* Given an array of strings words, return the first palindromic string in the array. If there is
7+
* no such string, return an empty string "".
8+
*
9+
* A string is palindromic if it reads the same forward and backward.
10+
*/
11+
12+
/**
13+
* @param {string[]} words
14+
* @return {string}
15+
*/
16+
var firstPalindrome = function(words) {
17+
for (const word of words) {
18+
if (word === word.split('').reverse().join('')) {
19+
return word;
20+
}
21+
}
22+
return '';
23+
};

0 commit comments

Comments
 (0)