From da4fb386510fd066477f8058f1f87eee23254f3e Mon Sep 17 00:00:00 2001 From: RitikaGupta8734 Date: Mon, 30 Aug 2021 15:05:18 +0530 Subject: [PATCH 01/16] feat: added z_algorithm in strings --- strings/z_function.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 strings/z_function.cpp diff --git a/strings/z_function.cpp b/strings/z_function.cpp new file mode 100644 index 00000000000..960edc6a1bf --- /dev/null +++ b/strings/z_function.cpp @@ -0,0 +1,75 @@ +/** + * @file + * @brief The Z function for finding occurences of a pattern + * within a piece of text with time and space complexity O(n + m) + * @details + * DESCRIPTION + * 1. The Z-function for a string is an array of length n where the + * i-th element is equal to the greatest number of characters starting + * from the position i that coincide with the first characters of s. + * 2. Eg string : ababb then z[2]=2 as s[2]=s[0] and s[3]=s[1] and s[4]!=s[2] + * LINK + * https://cp-algorithms.com/string/z-function.html + * @author [Ritika Gupta](https://github.com/RitikaGupta8734) + */ + +#include +#ifdef _MSC_VER +#include // use this for MS Visual C++ +#else +#include +#endif +#include +# include + +/** + * Generate the Z-function for the inputted string. + * \param[in] pattern text on which to apply the Z-function + * \returns the Z-function output as a vector array + */ +std::vector Z_function(const std::string &pattern) { + int pattern_length = pattern.size(); + std::vector z(pattern_length,0); + + for (int i = 1,l = 0,r = 0; i < pattern_length; i++) { + if(i<=r)z[i]=std::min(r-i+1,z[i-l]); + while(i+z[i]r)r=i+z[i]-1; + } + return z; +} + +/** + * Using Z_function to find a pattern in a text + * \param[in] pattern string pattern to search + * \param[in] text text in which to search + * \returns a vector of starting indexes where pattern is found in the text + */ +std::vector find_pat_in_text(const std::string &pattern, const std::string &text) { + int text_length = text.size(), pattern_length = pattern.size(); + std::vector z = Z_function(pattern+'#'+text); + std::vector matching_indexes; + + for (int i = 0; i < text_length; i++) { + if(z[i+pattern_length+1]==pattern_length) matching_indexes.push_back(i); + } + return matching_indexes; +} + + +/** Main function */ +int main() { + std::string text1 = "alskfjaldsabc1abc1abcbksbcdnsdabcabc"; + std::string pattern1 = "abc"; + + std::vector matching_indexes1=find_pat_in_text(pattern1,text1); + assert((matching_indexes1 == std::vector{10,14,18,30,33})); + + std::string text2 = "greengrass"; + std::string pattern2 = "abc"; + + std::vector matching_indexes2=find_pat_in_text(pattern2,text2); + assert((matching_indexes2 == std::vector{})); + + return 0; +} From ad4dad5ae37f23db5c9d9e84d2f9a56bc2a53a96 Mon Sep 17 00:00:00 2001 From: RitikaGupta8734 <43800283+RitikaGupta8734@users.noreply.github.com> Date: Tue, 31 Aug 2021 13:08:33 +0530 Subject: [PATCH 02/16] Updated z_function.cpp Updated z_function.cpp as per contribution guidelines. Fixed Link using github markdown syntax Created a separate function for tests and covered the corner case --- strings/z_function.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/strings/z_function.cpp b/strings/z_function.cpp index 960edc6a1bf..e3858a9f459 100644 --- a/strings/z_function.cpp +++ b/strings/z_function.cpp @@ -1,6 +1,6 @@ /** * @file - * @brief The Z function for finding occurences of a pattern + * @brief The [Z function](https://cp-algorithms.com/string/z-function.html) for finding occurences of a pattern * within a piece of text with time and space complexity O(n + m) * @details * DESCRIPTION @@ -8,8 +8,6 @@ * i-th element is equal to the greatest number of characters starting * from the position i that coincide with the first characters of s. * 2. Eg string : ababb then z[2]=2 as s[2]=s[0] and s[3]=s[1] and s[4]!=s[2] - * LINK - * https://cp-algorithms.com/string/z-function.html * @author [Ritika Gupta](https://github.com/RitikaGupta8734) */ @@ -56,20 +54,26 @@ std::vector find_pat_in_text(const std::string &pattern, const std::string return matching_indexes; } - -/** Main function */ -int main() { +void testing(){ + + // usual case std::string text1 = "alskfjaldsabc1abc1abcbksbcdnsdabcabc"; std::string pattern1 = "abc"; std::vector matching_indexes1=find_pat_in_text(pattern1,text1); assert((matching_indexes1 == std::vector{10,14,18,30,33})); + // corner case std::string text2 = "greengrass"; std::string pattern2 = "abc"; std::vector matching_indexes2=find_pat_in_text(pattern2,text2); assert((matching_indexes2 == std::vector{})); +} +/** Main function */ +int main() { + + testing(); return 0; } From 9addf17de4dfdd8288dd1e7c66cee86e588c162f Mon Sep 17 00:00:00 2001 From: RitikaGupta8734 <43800283+RitikaGupta8734@users.noreply.github.com> Date: Wed, 1 Sep 2021 09:48:51 +0530 Subject: [PATCH 03/16] Apply suggestions from code review More comments added to the code Co-authored-by: David Leal --- strings/z_function.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/strings/z_function.cpp b/strings/z_function.cpp index e3858a9f459..b2ec48a7aca 100644 --- a/strings/z_function.cpp +++ b/strings/z_function.cpp @@ -11,14 +11,14 @@ * @author [Ritika Gupta](https://github.com/RitikaGupta8734) */ -#include +#include /// for IO operations #ifdef _MSC_VER -#include // use this for MS Visual C++ +#include /// for string (use this for MS Visual C++) #else -#include +#include /// for string #endif -#include -# include +#include /// for std::vector +#include /// for assert /** * Generate the Z-function for the inputted string. From 757c109ac4ca3fcb1e8a83da8d54cb9203f29426 Mon Sep 17 00:00:00 2001 From: RitikaGupta8734 <43800283+RitikaGupta8734@users.noreply.github.com> Date: Wed, 1 Sep 2021 09:50:37 +0530 Subject: [PATCH 04/16] Apply suggestions from code review Some more documentation added as per contribution guidelines. Co-authored-by: David Leal --- strings/z_function.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/strings/z_function.cpp b/strings/z_function.cpp index b2ec48a7aca..6e827e40ef7 100644 --- a/strings/z_function.cpp +++ b/strings/z_function.cpp @@ -21,7 +21,7 @@ #include /// for assert /** - * Generate the Z-function for the inputted string. + * @brief Generate the Z-function for the inputted string. * \param[in] pattern text on which to apply the Z-function * \returns the Z-function output as a vector array */ @@ -38,7 +38,7 @@ std::vector Z_function(const std::string &pattern) { } /** - * Using Z_function to find a pattern in a text + * @brief Using Z_function to find a pattern in a text * \param[in] pattern string pattern to search * \param[in] text text in which to search * \returns a vector of starting indexes where pattern is found in the text @@ -54,7 +54,11 @@ std::vector find_pat_in_text(const std::string &pattern, const std::string return matching_indexes; } -void testing(){ +/** + * @brief Self-test implementations + * @returns void + */ +static void test(){ // usual case std::string text1 = "alskfjaldsabc1abc1abcbksbcdnsdabcabc"; @@ -71,7 +75,10 @@ void testing(){ assert((matching_indexes2 == std::vector{})); } -/** Main function */ +/** + * @brief Main function + * @returns 0 on exit + */ int main() { testing(); From b5cb054be90cc4d4ca25e6a147985cbaa4e2141c Mon Sep 17 00:00:00 2001 From: RitikaGupta8734 <43800283+RitikaGupta8734@users.noreply.github.com> Date: Wed, 1 Sep 2021 09:53:39 +0530 Subject: [PATCH 05/16] Update strings/z_function.cpp comments added Co-authored-by: David Leal --- strings/z_function.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/z_function.cpp b/strings/z_function.cpp index 6e827e40ef7..e477021d0c2 100644 --- a/strings/z_function.cpp +++ b/strings/z_function.cpp @@ -81,6 +81,6 @@ static void test(){ */ int main() { - testing(); + test(); // run self-test implementations return 0; } From 61cb76c6c6cdaa6408acfeb41a03d47945770eca Mon Sep 17 00:00:00 2001 From: RitikaGupta8734 <43800283+RitikaGupta8734@users.noreply.github.com> Date: Thu, 2 Sep 2021 01:03:11 +0530 Subject: [PATCH 06/16] Update strings/z_function.cpp Co-authored-by: David Leal --- strings/z_function.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/strings/z_function.cpp b/strings/z_function.cpp index e477021d0c2..e0941a73d63 100644 --- a/strings/z_function.cpp +++ b/strings/z_function.cpp @@ -59,7 +59,6 @@ std::vector find_pat_in_text(const std::string &pattern, const std::string * @returns void */ static void test(){ - // usual case std::string text1 = "alskfjaldsabc1abc1abcbksbcdnsdabcabc"; std::string pattern1 = "abc"; From c21293771d31494b17c757eb8fb51b886f8a2688 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Wed, 1 Sep 2021 19:34:00 +0000 Subject: [PATCH 07/16] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 0bd470d744a..43076a85e04 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -333,3 +333,4 @@ * [Knuth Morris Pratt](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/strings/knuth_morris_pratt.cpp) * [Manacher Algorithm](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/strings/manacher_algorithm.cpp) * [Rabin Karp](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/strings/rabin_karp.cpp) + * [Z Function](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/strings/z_function.cpp) From edff958ab2e3f06a5e43181b7b291bd7eb7294ef Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Wed, 1 Sep 2021 19:34:09 +0000 Subject: [PATCH 08/16] clang-format and clang-tidy fixes for 0c7515e9 --- strings/z_function.cpp | 61 +++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/strings/z_function.cpp b/strings/z_function.cpp index e0941a73d63..6056dd5aee5 100644 --- a/strings/z_function.cpp +++ b/strings/z_function.cpp @@ -1,24 +1,25 @@ /** * @file - * @brief The [Z function](https://cp-algorithms.com/string/z-function.html) for finding occurences of a pattern - * within a piece of text with time and space complexity O(n + m) - * @details + * @brief The [Z function](https://cp-algorithms.com/string/z-function.html) for + * finding occurences of a pattern within a piece of text with time and space + * complexity O(n + m) + * @details * DESCRIPTION - * 1. The Z-function for a string is an array of length n where the - * i-th element is equal to the greatest number of characters starting + * 1. The Z-function for a string is an array of length n where the + * i-th element is equal to the greatest number of characters starting * from the position i that coincide with the first characters of s. * 2. Eg string : ababb then z[2]=2 as s[2]=s[0] and s[3]=s[1] and s[4]!=s[2] * @author [Ritika Gupta](https://github.com/RitikaGupta8734) */ -#include /// for IO operations +#include /// for IO operations #ifdef _MSC_VER #include /// for string (use this for MS Visual C++) #else -#include /// for string +#include /// for string #endif -#include /// for std::vector -#include /// for assert +#include /// for assert +#include /// for std::vector /** * @brief Generate the Z-function for the inputted string. @@ -27,12 +28,15 @@ */ std::vector Z_function(const std::string &pattern) { int pattern_length = pattern.size(); - std::vector z(pattern_length,0); - - for (int i = 1,l = 0,r = 0; i < pattern_length; i++) { - if(i<=r)z[i]=std::min(r-i+1,z[i-l]); - while(i+z[i]r)r=i+z[i]-1; + std::vector z(pattern_length, 0); + + for (int i = 1, l = 0, r = 0; i < pattern_length; i++) { + if (i <= r) + z[i] = std::min(r - i + 1, z[i - l]); + while (i + z[i] < pattern_length && pattern[z[i]] == pattern[i + z[i]]) + z[i]++; + if (i + z[i] - 1 > r) + r = i + z[i] - 1; } return z; } @@ -41,36 +45,38 @@ std::vector Z_function(const std::string &pattern) { * @brief Using Z_function to find a pattern in a text * \param[in] pattern string pattern to search * \param[in] text text in which to search - * \returns a vector of starting indexes where pattern is found in the text + * \returns a vector of starting indexes where pattern is found in the text */ -std::vector find_pat_in_text(const std::string &pattern, const std::string &text) { +std::vector find_pat_in_text(const std::string &pattern, + const std::string &text) { int text_length = text.size(), pattern_length = pattern.size(); - std::vector z = Z_function(pattern+'#'+text); + std::vector z = Z_function(pattern + '#' + text); std::vector matching_indexes; for (int i = 0; i < text_length; i++) { - if(z[i+pattern_length+1]==pattern_length) matching_indexes.push_back(i); + if (z[i + pattern_length + 1] == pattern_length) + matching_indexes.push_back(i); } return matching_indexes; -} +} /** * @brief Self-test implementations * @returns void */ -static void test(){ +static void test() { // usual case std::string text1 = "alskfjaldsabc1abc1abcbksbcdnsdabcabc"; std::string pattern1 = "abc"; - - std::vector matching_indexes1=find_pat_in_text(pattern1,text1); - assert((matching_indexes1 == std::vector{10,14,18,30,33})); - + + std::vector matching_indexes1 = find_pat_in_text(pattern1, text1); + assert((matching_indexes1 == std::vector{10, 14, 18, 30, 33})); + // corner case std::string text2 = "greengrass"; std::string pattern2 = "abc"; - - std::vector matching_indexes2=find_pat_in_text(pattern2,text2); + + std::vector matching_indexes2 = find_pat_in_text(pattern2, text2); assert((matching_indexes2 == std::vector{})); } @@ -79,7 +85,6 @@ static void test(){ * @returns 0 on exit */ int main() { - test(); // run self-test implementations return 0; } From 12d512399590d2d177c9a26949dd0ff697e83c55 Mon Sep 17 00:00:00 2001 From: RitikaGupta8734 <43800283+RitikaGupta8734@users.noreply.github.com> Date: Thu, 2 Sep 2021 01:10:48 +0530 Subject: [PATCH 09/16] Updated int -> uint64_t Updated int -> uint64_t for non-negative values --- strings/z_function.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/strings/z_function.cpp b/strings/z_function.cpp index 6056dd5aee5..8493e8a9cab 100644 --- a/strings/z_function.cpp +++ b/strings/z_function.cpp @@ -26,11 +26,11 @@ * \param[in] pattern text on which to apply the Z-function * \returns the Z-function output as a vector array */ -std::vector Z_function(const std::string &pattern) { - int pattern_length = pattern.size(); - std::vector z(pattern_length, 0); +std::vector Z_function(const std::string &pattern) { + uint64_t pattern_length = pattern.size(); + std::vector z(pattern_length, 0); - for (int i = 1, l = 0, r = 0; i < pattern_length; i++) { + for (uint64_t i = 1, l = 0, r = 0; i < pattern_length; i++) { if (i <= r) z[i] = std::min(r - i + 1, z[i - l]); while (i + z[i] < pattern_length && pattern[z[i]] == pattern[i + z[i]]) @@ -47,13 +47,13 @@ std::vector Z_function(const std::string &pattern) { * \param[in] text text in which to search * \returns a vector of starting indexes where pattern is found in the text */ -std::vector find_pat_in_text(const std::string &pattern, +std::vector find_pat_in_text(const std::string &pattern, const std::string &text) { - int text_length = text.size(), pattern_length = pattern.size(); - std::vector z = Z_function(pattern + '#' + text); - std::vector matching_indexes; + uint64_t text_length = text.size(), pattern_length = pattern.size(); + std::vector z = Z_function(pattern + '#' + text); + std::vector matching_indexes; - for (int i = 0; i < text_length; i++) { + for (uint64_t i = 0; i < text_length; i++) { if (z[i + pattern_length + 1] == pattern_length) matching_indexes.push_back(i); } @@ -69,15 +69,15 @@ static void test() { std::string text1 = "alskfjaldsabc1abc1abcbksbcdnsdabcabc"; std::string pattern1 = "abc"; - std::vector matching_indexes1 = find_pat_in_text(pattern1, text1); - assert((matching_indexes1 == std::vector{10, 14, 18, 30, 33})); + std::vector matching_indexes1 = find_pat_in_text(pattern1, text1); + assert((matching_indexes1 == std::vector{10, 14, 18, 30, 33})); // corner case std::string text2 = "greengrass"; std::string pattern2 = "abc"; - std::vector matching_indexes2 = find_pat_in_text(pattern2, text2); - assert((matching_indexes2 == std::vector{})); + std::vector matching_indexes2 = find_pat_in_text(pattern2, text2); + assert((matching_indexes2 == std::vector{})); } /** From 910cb68780f2944a43fcf4900c079d8ac8f5c1f2 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Wed, 1 Sep 2021 19:41:33 +0000 Subject: [PATCH 10/16] clang-format and clang-tidy fixes for 12d51239 --- strings/z_function.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/strings/z_function.cpp b/strings/z_function.cpp index 8493e8a9cab..7f61db0d89f 100644 --- a/strings/z_function.cpp +++ b/strings/z_function.cpp @@ -31,12 +31,16 @@ std::vector Z_function(const std::string &pattern) { std::vector z(pattern_length, 0); for (uint64_t i = 1, l = 0, r = 0; i < pattern_length; i++) { - if (i <= r) + if (i <= r) { z[i] = std::min(r - i + 1, z[i - l]); - while (i + z[i] < pattern_length && pattern[z[i]] == pattern[i + z[i]]) + } + while (i + z[i] < pattern_length && + pattern[z[i]] == pattern[i + z[i]]) { z[i]++; - if (i + z[i] - 1 > r) + } + if (i + z[i] - 1 > r) { r = i + z[i] - 1; + } } return z; } @@ -48,14 +52,15 @@ std::vector Z_function(const std::string &pattern) { * \returns a vector of starting indexes where pattern is found in the text */ std::vector find_pat_in_text(const std::string &pattern, - const std::string &text) { + const std::string &text) { uint64_t text_length = text.size(), pattern_length = pattern.size(); std::vector z = Z_function(pattern + '#' + text); std::vector matching_indexes; for (uint64_t i = 0; i < text_length; i++) { - if (z[i + pattern_length + 1] == pattern_length) + if (z[i + pattern_length + 1] == pattern_length) { matching_indexes.push_back(i); + } } return matching_indexes; } From 0737aff7a31b300b99747a24ab928be6d6305cbd Mon Sep 17 00:00:00 2001 From: RitikaGupta8734 <43800283+RitikaGupta8734@users.noreply.github.com> Date: Thu, 2 Sep 2021 09:40:42 +0530 Subject: [PATCH 11/16] Update strings/z_function.cpp Co-authored-by: David Leal --- strings/z_function.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/strings/z_function.cpp b/strings/z_function.cpp index 7f61db0d89f..3cc89e520a9 100644 --- a/strings/z_function.cpp +++ b/strings/z_function.cpp @@ -4,7 +4,6 @@ * finding occurences of a pattern within a piece of text with time and space * complexity O(n + m) * @details - * DESCRIPTION * 1. The Z-function for a string is an array of length n where the * i-th element is equal to the greatest number of characters starting * from the position i that coincide with the first characters of s. From c9919d6605a5b3f7a4e7a0e126087397901b807b Mon Sep 17 00:00:00 2001 From: RitikaGupta8734 <43800283+RitikaGupta8734@users.noreply.github.com> Date: Thu, 2 Sep 2021 09:41:00 +0530 Subject: [PATCH 12/16] Update strings/z_function.cpp Co-authored-by: David Leal --- strings/z_function.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/z_function.cpp b/strings/z_function.cpp index 3cc89e520a9..a3fc0735b98 100644 --- a/strings/z_function.cpp +++ b/strings/z_function.cpp @@ -7,7 +7,7 @@ * 1. The Z-function for a string is an array of length n where the * i-th element is equal to the greatest number of characters starting * from the position i that coincide with the first characters of s. - * 2. Eg string : ababb then z[2]=2 as s[2]=s[0] and s[3]=s[1] and s[4]!=s[2] + * 2. E.g.: string: ababb then z[2]=2 as s[2]=s[0] and s[3]=s[1] and s[4]!=s[2] * @author [Ritika Gupta](https://github.com/RitikaGupta8734) */ From 8a627ac9b7e04c4e5a3b327b462ebf1c5378a8b3 Mon Sep 17 00:00:00 2001 From: RitikaGupta8734 <43800283+RitikaGupta8734@users.noreply.github.com> Date: Thu, 2 Sep 2021 22:14:27 +0530 Subject: [PATCH 13/16] More comments added --- strings/z_function.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/strings/z_function.cpp b/strings/z_function.cpp index a3fc0735b98..cb7667d8216 100644 --- a/strings/z_function.cpp +++ b/strings/z_function.cpp @@ -72,7 +72,8 @@ static void test() { // usual case std::string text1 = "alskfjaldsabc1abc1abcbksbcdnsdabcabc"; std::string pattern1 = "abc"; - + + // matching_indexes1 gets the indexes where pattern1 exists in text1 std::vector matching_indexes1 = find_pat_in_text(pattern1, text1); assert((matching_indexes1 == std::vector{10, 14, 18, 30, 33})); @@ -80,6 +81,7 @@ static void test() { std::string text2 = "greengrass"; std::string pattern2 = "abc"; + // matching_indexes2 gets the indexes where pattern2 exists in text2 std::vector matching_indexes2 = find_pat_in_text(pattern2, text2); assert((matching_indexes2 == std::vector{})); } From 02aae78cc052a0984303c7bdcf29b6d29689373f Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Thu, 2 Sep 2021 16:45:05 +0000 Subject: [PATCH 14/16] clang-format and clang-tidy fixes for 8a627ac9 --- strings/z_function.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/z_function.cpp b/strings/z_function.cpp index cb7667d8216..a063146ef0d 100644 --- a/strings/z_function.cpp +++ b/strings/z_function.cpp @@ -72,7 +72,7 @@ static void test() { // usual case std::string text1 = "alskfjaldsabc1abc1abcbksbcdnsdabcabc"; std::string pattern1 = "abc"; - + // matching_indexes1 gets the indexes where pattern1 exists in text1 std::vector matching_indexes1 = find_pat_in_text(pattern1, text1); assert((matching_indexes1 == std::vector{10, 14, 18, 30, 33})); From 8ee1415b674da893c1f0b2cf390660895c2a626d Mon Sep 17 00:00:00 2001 From: RitikaGupta8734 <43800283+RitikaGupta8734@users.noreply.github.com> Date: Fri, 3 Sep 2021 12:05:28 +0530 Subject: [PATCH 15/16] Update strings/z_function.cpp Co-authored-by: David Leal --- strings/z_function.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/z_function.cpp b/strings/z_function.cpp index a063146ef0d..95fbd975e48 100644 --- a/strings/z_function.cpp +++ b/strings/z_function.cpp @@ -73,7 +73,7 @@ static void test() { std::string text1 = "alskfjaldsabc1abc1abcbksbcdnsdabcabc"; std::string pattern1 = "abc"; - // matching_indexes1 gets the indexes where pattern1 exists in text1 + // matching_indexes1 gets the indexes where pattern1 exists in text1 std::vector matching_indexes1 = find_pat_in_text(pattern1, text1); assert((matching_indexes1 == std::vector{10, 14, 18, 30, 33})); From 88796b20cd597600431010b9f409a2cb56967528 Mon Sep 17 00:00:00 2001 From: RitikaGupta8734 <43800283+RitikaGupta8734@users.noreply.github.com> Date: Fri, 3 Sep 2021 12:05:52 +0530 Subject: [PATCH 16/16] Update strings/z_function.cpp Co-authored-by: David Leal --- strings/z_function.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/z_function.cpp b/strings/z_function.cpp index 95fbd975e48..6ce98c491d1 100644 --- a/strings/z_function.cpp +++ b/strings/z_function.cpp @@ -81,7 +81,7 @@ static void test() { std::string text2 = "greengrass"; std::string pattern2 = "abc"; - // matching_indexes2 gets the indexes where pattern2 exists in text2 + // matching_indexes2 gets the indexes where pattern2 exists in text2 std::vector matching_indexes2 = find_pat_in_text(pattern2, text2); assert((matching_indexes2 == std::vector{})); }