标签:tar info for class else https lan href ted
题目链接:串联字符串的最大长度
题目描述:
题解:
class Solution {
public:
int maxLen = 0;
void backTracking(vector<string>& arr, int index, vector<int>& letters)
{
int len = 0;
//整个回溯过程中是否有重复字符
for (auto n : letters)
{
if (n >= 2)
return;
else if(n == 1)
len++;
}
maxLen = max(len, maxLen);
//递归出口
if(index == arr.size())
return;
//本身存在重复字符
for (auto c : arr[index])
{
if (letters[c - ‘a‘] > 1)
return;
}
for(int i = index; i < arr.size(); ++i)
{
for(auto ch: arr[i])
letters[ch - ‘a‘]++;
backTracking(arr, i + 1, letters);
for(auto ch: arr[i])
letters[ch - ‘a‘]--;
}
}
int maxLength(vector<string>& arr) {
vector<int> letters(26, 0);
backTracking(arr, 0, letters);
return maxLen;
}
};
标签:tar info for class else https lan href ted
原文地址:https://www.cnblogs.com/ZigHello/p/14903547.html