mirror of
https://github.com/mudabbir-ahmad/Leet-Code-prog.git
synced 2026-10-07 18:30:20 +00:00
sol
This commit is contained in:
1 parent
e9cadfe0a4
commit
9888be26db
1 file changed
+8
@@ -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
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in new issue
Block a user