problem 1071. Greatest Common Divisor of Strings solution class Solution { public: string gcdOfStrings(string str1, string str2) { return (str1+str2==str2+str1) ? (str1.substr(, gcd(str1.size(), str2.size()))) : ""; } }; 参考 1. Leetcode_easy_1071…
题目如下: For strings S and T, we say "T divides S" if and only if S = T + ... + T  (T concatenated with itself 1 or more times) Return the largest string X such that X divides str1 and X divides str2. Example 1: Input: str1 = "ABCABC", st…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力遍历 日期 题目地址:https://leetcode.com/problems/greatest-common-divisor-of-strings/ 题目描述 For strings S and T, we say "T divides S" if and only if S = T + ... + T (T concatenate…
lc1071 Greatest Common Divisor of Strings 找两个字符串的最长公共子串 假设:str1.length > str2.length 因为是公共子串,所以str2一定可以和str1前面一部分匹配上,否则不存在公共子串. 所以我们比较str2和str1的0~str2.length()-1部分, 若不同,则直接返回””,不存在公共子串. 若相同,继续比较str2和str1的剩下部分,这里就是递归了,调用原函数gcd(str2, str1.substring(str…
1071. 字符串的最大公因子 1071. Greatest Common Divisor of Strings 题目描述 对于字符串 S 和 T,只有在 S = T + ... + T(T 与自身连接 1 次或多次)时,我们才认定 "T 能除尽 S". 返回字符串 X,要求满足 X 能除尽 str1 且 X 能除尽 str2. 每日一算法2019/6/17Day 45LeetCode1071. Greatest Common Divisor of Strings 示例 1: 输入:s…
这是小川的第391次更新,第421篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第253题(顺位题号是1071).对于字符串S和T,当且仅当S = T + ... + T(T与自身连接1次或更多次)时,我们说"T除S". 返回最大的字符串X,使得X除以str1,X除以str2. 例如: 输入:str1 ="ABCABC",str2 ="ABC" 输出:"ABC" 输入:str1 ="AB…
problem 819. Most Common Word solution: class Solution { public: string mostCommonWord(string paragraph, vector<string>& banned) { unordered_map<string, int> m; string word = ""; ; i<paragraph.size(); ) { string word = "&…
LCIS /* 1423 */ #include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 505 int a[MAXN]; int b[MAXN]; int c[MAXN]; int n, m; int ans; int max(int a, int b) { return a>b ? a:b; } void solve() { int i, j, k; memset(c, , siz…
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/)➤GitHub地址:https://github.com/strengthen/LeetCode➤原文地址:https://www.cnblogs.com/strengthen/p/10961892.html ➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章…
Greatest Common Divisor 题目链接 题目描述 There is an array of length n, containing only positive numbers. Now you can add all numbers by 1 many times. Please find out the minimum times you need to perform to obtain an array whose greatest common divisor(gcd…