From 9888be26db1002b7f14d84f86be7345fb3f49a15 Mon Sep 17 00:00:00 2001 From: mudabbir-ahmad Date: Fri, 8 May 2026 18:56:16 +0100 Subject: [PATCH] sol --- Easy/Common_Divisor_Of_Two_Strings/Solution.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Easy/Common_Divisor_Of_Two_Strings/Solution.cpp diff --git a/Easy/Common_Divisor_Of_Two_Strings/Solution.cpp b/Easy/Common_Divisor_Of_Two_Strings/Solution.cpp new file mode 100644 index 0000000..a3d8fee --- /dev/null +++ b/Easy/Common_Divisor_Of_Two_Strings/Solution.cpp @@ -0,0 +1,8 @@ +class Solution { +public: + string gcdOfStrings(string str1, string str2) { + return (str1 + str2 == str2 + str1)? // if adding str2 to the start is the same as adding it to the end (if they're the same it's just repeated same thing) == true then + str1.substr(0, gcd(size(str1),size(str2))) // whats being returned = SUBSTRING starting from 0 to the gcd ( COMMON DIVISOR FOR ) the size of str1 and str2 + : ""; // else return nothing + } +}; \ No newline at end of file