diff --git a/2202/220202-CN.cpp b/2202/220202-CN.cpp index 1379285..03a2535 100644 --- a/2202/220202-CN.cpp +++ b/2202/220202-CN.cpp @@ -1,6 +1,13 @@ #include #include +/** + * 2000. Reverse Prefix of Word + * Given a 0-indexed string word and a character ch, reverse the segment of word that starts at index 0 and ends at the index of the first occurrence of ch (inclusive). If the character ch does not exist in word, do nothing. + * For example, if word = "abcdefd" and ch = "d", then you should reverse the segment that starts at 0 and ends at 3 (inclusive). The resulting string will be "dcbaefd". + * Return the resulting string. + */ + class Solution { public: static std::string reversePrefix(std::string word, char ch) { diff --git a/2202/220202.cpp b/2202/220202.cpp index f00539e..e615bdc 100644 --- a/2202/220202.cpp +++ b/2202/220202.cpp @@ -1,6 +1,12 @@ #include #include +/** + * 438. Find All Anagrams in a String + * Given two strings s and p, return an array of all the start indices of p's anagrams in s. You may return the answer in any order. + * An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. + */ + class Solution { private: template diff --git a/2202/220203-CN.cpp b/2202/220203-CN.cpp index d7578cc..faaea7d 100644 --- a/2202/220203-CN.cpp +++ b/2202/220203-CN.cpp @@ -4,6 +4,18 @@ #include #include +/** + * 1414. Find the Minimum Number of Fibonacci Numbers Whose Sum Is K + * Given an integer k, return the minimum number of Fibonacci numbers whose sum is equal to k. The same Fibonacci number can be used multiple times. + * + * The Fibonacci numbers are defined as: + * + * F[1] = 1 + * F[2] = 1 + * F[n] = F[n-1] + F[n-2] for n > 2. + * It is guaranteed that for the given constraints we can always find such Fibonacci numbers that sum up to k. + */ + class Solution { private: inline static constexpr int fib[] = {1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903}; diff --git a/2202/220203.cpp b/2202/220203.cpp index f237c84..43c9485 100644 --- a/2202/220203.cpp +++ b/2202/220203.cpp @@ -2,6 +2,13 @@ #include #include +/** + * 454. 4Sum II + * Given four integer arrays nums1, nums2, nums3, and nums4 all of length n, return the number of tuples (i, j, k, l) such that: + * 0 <= i, j, k, l < n + * nums1[i] + nums2[j] + nums3[k] + nums4[l] == 0 + */ + class Solution { public: static int fourSumCount(const std::vector& nums1, const std::vector& nums2, const std::vector& nums3, const std::vector& nums4) {