Skip to content

Commit

Permalink
Time: 59 ms (92.28%) | Memory: 52.5 MB (49.40%) - LeetSync
Browse files Browse the repository at this point in the history
  • Loading branch information
ShatilKhan committed Feb 13, 2024
1 parent d7f196f commit ef771b5
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @param {string[]} words
* @return {string}
*/
var firstPalindrome = function(words) {
let solution = new Solution();
return solution.firstPalindrome(words);
};

class Solution {
check(s) {
let i = 0, j = s.length - 1;
while (i <= j) {
if (s[i] === s[j]) {
i++;
j--;
} else {
return false;
}
}
return true;
}

firstPalindrome(words) {
for (let word of words) {
if (this.check(word)) {
return word;
}
}
return "";
}
}

0 comments on commit ef771b5

Please sign in to comment.