2023年12月第4周面试算法题总结

809. 情感丰富的文字------阅读理解题

1、s = "abcd"; words = ["abc"]; 的情况怎么处理

2、怎么求lens与lenw?(连续出现的字符串长度)

cpp 复制代码
class Solution {
public:
bool isStretchy(const string& s, const string& word) {
    int i = 0;
    int j = 0;
    while (i < s.size() && j < word.size()) {
        if (s[i] != word[j]) {
            return false;
        }
        int lens = 0;
        int lenw = 0;
        while (i + lens < s.size() && s[i + lens] == s[i]) {
            lens++;
        }
        while (j + lenw < word.size() && word[j + lenw] == word[j]) {
            lenw++;
        }
        if ((lens < 3 && lens != lenw) || (lenw == 0 && lens != 0) || (lens < lenw)) {
            return false;
        }
        i += lens;
        j += lenw;
    }
    return i == s.size() && j == word.size();
}
    int expressiveWords(string s, vector<string>& words) {
        int count = 0;
        for (int i = 0; i < words.size(); i++) {
            if (isStretchy(s, words[i])) {
                count++;
            }
        }
        return count;
    }
};
相关推荐
一个不知名程序员www1 小时前
算法学习入门---vector(C++)
c++·算法
云飞云共享云桌面1 小时前
无需配置传统电脑——智能装备工厂10个SolidWorks共享一台工作站
运维·服务器·前端·网络·算法·电脑
福尔摩斯张1 小时前
《C 语言指针从入门到精通:全面笔记 + 实战习题深度解析》(超详细)
linux·运维·服务器·c语言·开发语言·c++·算法
橘颂TA1 小时前
【剑斩OFFER】算法的暴力美学——两整数之和
算法·leetcode·职场和发展
xxxxxxllllllshi2 小时前
【LeetCode Hot100----14-贪心算法(01-05),包含多种方法,详细思路与代码,让你一篇文章看懂所有!】
java·数据结构·算法·leetcode·贪心算法
前端小L2 小时前
图论专题(二十二):并查集的“逻辑审判”——判断「等式方程的可满足性」
算法·矩阵·深度优先·图论·宽度优先
铁手飞鹰2 小时前
二叉树(C语言,手撕)
c语言·数据结构·算法·二叉树·深度优先·广度优先
专业抄代码选手4 小时前
【Leetcode】1930. 长度为 3 的不同回文子序列
javascript·算法·面试
[J] 一坚4 小时前
深入浅出理解冒泡、插入排序和归并、快速排序递归调用过程
c语言·数据结构·算法·排序算法
czlczl200209254 小时前
算法:二叉搜索树的最近公共祖先
算法