leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit 15e8ea0ae319cb32dd524d8fc5835600d58bcae6
parent ab390eb45334ea1a668699475116fd0e744b1a92
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Tue, 13 Feb 2024 20:10:57 +0000

Daily Problem

Diffstat:
AProblems/2108.cpp | 18++++++++++++++++++
MREADME.md | 1+
2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/Problems/2108.cpp b/Problems/2108.cpp @@ -0,0 +1,18 @@ +class Solution { + static bool isPalindrome(const string &s) { + int i = 0, j = size(s) - 1; + while (i < j) { + if (s[i] != s[j]) return false; + i++, j--; + } + return true; + } + + public: + string firstPalindrome(const vector<string> &words) const { + for (const string &word : words) { + if (isPalindrome(word)) return word; + } + return ""; + } +}; diff --git a/README.md b/README.md @@ -969,6 +969,7 @@ for solving problems. | 2095 | Medium | [Delete the Middle Node of a Linked List](Problems/2095.cpp) | | 2101 | Medium | [Detonate the Maximum Bombs](Problems/2101.cpp) | | 2104 | Medium | [Sum of Subarray Ranges](Problems/2104.cpp) | +| 2108 | Easy | [Find First Palindromic String in the Array](Problems/2108.cpp) | | 2109 | Medium | [Adding Spaces to a String](Problems/2109.cpp) | | 2110 | Medium | [Number of Smooth Descent Periods of a Stock](Problems/2110.cpp) | | 2115 | Medium | [Find All Possible Recipes from Given Supplies](Problems/2115.cpp) |