Leetcode—1239. 串联字符串的最大长度【中等】(unordered_set)
2024每日刷题(155)
Leetcode—1239. 串联字符串的最大长度
实现代码
class Solution {
public:bool charSet(string & s) {unordered_set<char> charSet(s.begin(), s.end());// true表示有重复// false表示唯一return s.size() != charSet.size();}int maxLength(vector<string>& arr) {vector<string> res;for(string& s: arr) {int n = res.size();for(int i = 0; i < n; i++) {string tmp = res[i] + s;if(!charSet(tmp)) {res.push_back(tmp);}}if(!charSet(s)) {res.push_back(s);}}int maxValue = 0;for(string& s: res) {maxValue = max(maxValue, s.size());}return maxValue;}
};
运行结果
之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!