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;
    }
};
相关推荐
json{shen:"jing"}20 分钟前
1-C语言的数据类型
c语言·c++·算法
im_AMBER34 分钟前
数据结构 13 图 | 哈希表 | 树
数据结构·笔记·学习·算法·散列表
LYFlied42 分钟前
【算法解题模板】动态规划:从暴力递归到优雅状态转移的进阶之路
数据结构·算法·leetcode·面试·动态规划
Hcoco_me1 小时前
RTMPose_JSON相关解读
算法·数据挖掘·json·聚类
高洁011 小时前
DNN案例一步步构建深层神经网络(二)
人工智能·python·深度学习·算法·机器学习
aini_lovee1 小时前
改进遗传算法求解VRP问题时的局部搜索能力
开发语言·算法·matlab
老蒋新思维2 小时前
反脆弱性设计:创始人IP与AI智能体如何构建愈动荡愈强大的知识商业|创客匠人
人工智能·网络协议·tcp/ip·算法·机器学习·创始人ip·创客匠人
Salt_07282 小时前
DAY 36 官方文档的阅读
python·算法·机器学习·github
明洞日记3 小时前
【VTK手册027】VTK 颜色连续映射:vtkColorTransferFunction 深度解析与实战指南
c++·图像处理·算法·vtk·图形渲染
B_lack0263 小时前
西门子PLC结构化编程_线性插值算法功能块
算法·pid·西门子plc·博途·线性插值·开环控制