文章目录
- 100166. 检查按位或是否存在尾随零
- 题目
- 题意
- 代码
 
- 100185. 找出出现至少三次的最长特殊子字符串 I
- 题目
- 思路
- 代码
 
- 100184. 找出出现至少三次的最长特殊子字符串 II
100166. 检查按位或是否存在尾随零
题目

题意
这里题目要求的是或运算,所以原数组中只需要有两个或者两个以上的数字是满足存在一个尾随零条件即可
代码
class Solution {
public:
    bool hasTrailingZeros(vector<int>& nums) {
        int n=nums.size();
        int ans=0;
        for(int i=0;i<n;++i)
            if(nums[i]%2==0)ans++;
        if(ans>=2)return true;
        return false;
    }
};
100185. 找出出现至少三次的最长特殊子字符串 I
题目

思路
这个问题可以通过先统计字符串中相同字母的连续出现长度,然后按长度从大到小排序。接下来,按照规则处理这些长度。
从最长的特殊子串中取三个长度均为 (a[0] - 2) 的特殊子串。
 从最长和次长的特殊子串中取三个长度一样的特殊子串:
 如果 a[0] = a[1],取三个长度均为 (a[0] - 1) 的特殊子串。
 如果 a[0] > a[1],取三个长度均为 a[1] 的特殊子串:从最长中取两个,从次长中取一个。
 即为 min(a[0] - 1, a[1])。
 从最长、次长、第三长的特殊子串中各取一个长为 a[2] 的特殊子串。
 这三种情况取最大值,即为 max(a[0] - 2, min(a[0] - 1, a[1]), a[2])。
 最后,取每一组的最大值,即为答案。如果答案是 0,返回 -1。
代码
class Solution {
public:
    int maximumLength(string s) {
        vector<int> charGroups[26];
        int counter = 0, length = s.length();
        for (int i = 0; i < length; i++) {
            counter++;
            if (i + 1 == length || s[i] != s[i + 1]) {
                charGroups[s[i] - 'a'].push_back(counter);
                counter = 0;
            }
        }
        int result = 0;
        for (auto &group: charGroups) {
            if (group.empty()) continue;
            sort(group.rbegin(), group.rend());
            group.push_back(0);
            group.push_back(0); // 假设还有两个空串
            result = max({result, group[0] - 2, min(group[0] - 1, group[1]), group[2]});
        }
        return result ? result : -1;
    }
};
100184. 找出出现至少三次的最长特殊子字符串 II
做法同上



















![[DAU-FI Net开源 | Dual Attention UNet+特征融合+Sobel和Canny等算子解决语义分割痛点]](https://img-blog.csdnimg.cn/direct/8df44dcb68254860bc6cff17be93b66d.png)