leetcode 2981.找出出现至少三次的最长子特殊字符串(纯哈希表暴力)

leetcode 2981.找出出现至少三次的最长子特殊字符串(传送门)

cpp 复制代码
class Solution {
public:
    int maximumLength(string s) {
        int hash[30][52] = { 0 },len = 1,maxn=0;
        char last = 'A';
        for (char ch : s) {
            if (ch == last) len++;
            else len = 1;
            for (int i = len; i > 0; i--) {
                if(++hash[ch-'a'][i]>=3){
                    if(i>maxn)
                        maxn=i;
                    break;
                }
            }
            last = ch;
        }
        return maxn?maxn:-1;
    }
};
相关推荐
豆浩宇21 小时前
Conda环境隔离和PyCharm配置,完美同时运行PaddlePaddle和PyTorch
人工智能·pytorch·算法·计算机视觉·pycharm·conda·paddlepaddle
一只鱼^_21 小时前
牛客周赛 Round 108
数据结构·c++·算法·动态规划·图论·广度优先·推荐算法
小刘的AI小站1 天前
leetcode hot100 二叉搜索树
算法·leetcode
自信的小螺丝钉1 天前
Leetcode 876. 链表的中间结点 快慢指针
算法·leetcode·链表·指针
红豆怪怪1 天前
[LeetCode 热题 100] 32. 最长有效括号
数据结构·python·算法·leetcode·动态规划·代理模式
参.商.1 天前
【Day21】146.LRU缓存 (Least Recently Used)
leetcode·缓存·golang
愚润求学1 天前
【贪心算法】day6
c++·算法·leetcode·贪心算法
AI 嗯啦1 天前
计算机的排序方法
数据结构·算法·排序算法
l12345sy1 天前
Day23_【机器学习—聚类算法—K-Means聚类 及评估指标SSE、SC、CH】
算法·机器学习·kmeans·聚类·sse·sc·ch
_Coin_-1 天前
算法训练营DAY58 第十一章:图论part08
数据结构·算法·图论