leetcode

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

commit 16d5ff90c716ad7ee687ae3f6ee4ee7d9f9fc71c
parent 69adffa2824c91f6bf332c6c3150941436d877fa
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Wed, 18 Sep 2024 20:33:27 +0200

1 Random Problem

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

diff --git a/Problems/0718.cpp b/Problems/0718.cpp @@ -0,0 +1,18 @@ +class Solution { + public: + int findLength(const vector<int> &nums1, const vector<int> &nums2) const { + static int dp[1002][1002]; + int res = 0; + + memset(dp, 0x00, sizeof(dp)); + for (int i = size(nums1) - 1; i >= 0; i--) { + for (int j = size(nums2) - 1; j >= 0; j--) { + if (nums1[i] != nums2[j]) continue; + dp[i][j] = dp[i + 1][j + 1] + 1; + res = max(res, dp[i][j]); + } + } + + return res; + } +}; diff --git a/README.md b/README.md @@ -478,6 +478,7 @@ for solving problems. | 0712 | Medium | [Minimum ASCII Delete Sum for Two Strings](Problems/0712.cpp) | | 0713 | Medium | [Subarray Product Less Than K](Problems/0713.cpp) | | 0714 | Medium | [Best Time to Buy and Sell Stock with Transaction Fee](Problems/0714.cpp) | +| 0718 | Medium | [Maximum Length of Repeated Subarray](Problems/0718.cpp) | | 0719 | Hard | [Find K-th Smallest Pair Distance](Problems/0719.cpp) | | 0720 | Medium | [Longest Word in Dictionary](Problems/0720.cpp) | | 0724 | Easy | [Find Pivot Index](Problems/0724.cpp) |