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;
    }
};
相关推荐
2601_967760785 小时前
2026年PDF压缩与页码添加工具技术实测:性能、算法与本地化适配深度对比
算法·pdf
不会就选b6 小时前
算法日常・每日刷题--<贪心>7
数据结构·算法·leetcode
moonrailgun7 小时前
用 Node.js 复刻 Codex Astra 的终端星光
前端·javascript·算法
罗西的思考7 小时前
[Agent Memory / 强化学习] MemPO源码学习笔记 ---(1)--- 总体
人工智能·算法·机器学习
lvwangshu8 小时前
图论:LCA、树的直径、树的重心、二分图与 Tarjan 缩点
算法·图论
302wanger9 小时前
干与湿:AI 拿走脑力之后,人剩下什么
算法
计算机编程-吉哥9 小时前
脑肿瘤MRI智能识别系统:基于深度学习的像素级脑肿瘤语义分割平台【计算机毕业设计选题推荐】
人工智能·python·深度学习·算法·毕业设计·课程设计·大数据毕业设计选题推荐
用户2049375549510 小时前
端侧语音部署踩坑:模型能跑不等于终端真的能用
后端·算法
shehuiyuelaiyuehao10 小时前
算法39,位运算,消失的两个数字
java·数据结构·算法
ZiLing10 小时前
2026 ROS 2 Lyrical 踩坑实录(一):编译与依赖——rosdep、现代 CMake 与 CMake 4.x
算法