leetcode

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

0718.cpp (508B)


      1 class Solution {
      2   public:
      3     int findLength(const vector<int> &nums1, const vector<int> &nums2) const {
      4         static int dp[1002][1002];
      5         int res = 0;
      6 
      7         memset(dp, 0x00, sizeof(dp));
      8         for (int i = size(nums1) - 1; i >= 0; i--) {
      9             for (int j = size(nums2) - 1; j >= 0; j--) {
     10                 if (nums1[i] != nums2[j]) continue;
     11                 dp[i][j] = dp[i + 1][j + 1] + 1;
     12                 res = max(res, dp[i][j]);
     13             }
     14         }
     15 
     16         return res;
     17     }
     18 };