leetcode

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

commit de5b50c4f9389c84a4e30d07a99e4338741867c8
parent 68e28b853cb3834ccec809f44fc186ba7e129420
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sun,  6 Oct 2024 20:51:07 +0200

Daily Problem

Diffstat:
AProblems/1813.cpp | 24++++++++++++++++++++++++
MREADME.md | 1+
2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/Problems/1813.cpp b/Problems/1813.cpp @@ -0,0 +1,24 @@ +class Solution { + public: + bool areSentencesSimilar(const string &sentence1, const string &sentence2) const { + stringstream ss1(sentence1), ss2(sentence2); + vector<string> s1, s2; + string word; + + while (getline(ss1, word, ' ')) + s1.push_back(word); + while (getline(ss2, word, ' ')) + s2.push_back(word); + + if (size(s1) > size(s2)) swap(s1, s2); + + int i = 0, j = 0; + const int n = size(s1), m = size(s2); + while (i < n && s1[i] == s2[i]) + i++; + while (j < n && s1[n - j - 1] == s2[m - j - 1]) + j++; + + return i + j >= n; + } +}; diff --git a/README.md b/README.md @@ -1015,6 +1015,7 @@ for solving problems. | 1802 | Medium | [Maximum Value at a Given Index in a Bounded Array](Problems/1802.cpp) | | 1806 | Medium | [Minimum Number of Operations to Reinitialize a Permutation](Problems/1806.cpp) | | 1807 | Medium | [Evaluate the Bracket Pairs of a String](Problems/1807.cpp) | +| 1813 | Medium | [Sentence Similarity III](Problems/1813.cpp) | | 1814 | Medium | [Count Nice Pairs in an Array](Problems/1814.cpp) | | 1817 | Medium | [Finding the Users Active Minutes](Problems/1817.cpp) | | 1822 | Easy | [Sign of the Product of an Array](Problems/1822.cpp) |