From ac5da96f777622bc79670727e48167f738c3b9b4 Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Wed, 8 Jan 2025 15:43:58 +0530 Subject: [PATCH] Create 3042. Count Prefix and Suffix Pairs I --- 3042. Count Prefix and Suffix Pairs I | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 3042. Count Prefix and Suffix Pairs I diff --git a/3042. Count Prefix and Suffix Pairs I b/3042. Count Prefix and Suffix Pairs I new file mode 100644 index 0000000..694fbf5 --- /dev/null +++ b/3042. Count Prefix and Suffix Pairs I @@ -0,0 +1,29 @@ +class Solution { +public: + bool isPrefix(string word1, string word2){ + if(word1.size() > word2.size()) return false; + for(int i=0; i word2.size()) return false; + int i=word1.size()-1, j=word2.size()-1; + while(i>=0){ + if(word1[i] != word2[j]) return false; + i--, j--; + } + return true; + } + int countPrefixSuffixPairs(vector& words) { + int count = 0; + for(int i=0; i