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;
    }
};
相关推荐
fengfuyao9854 分钟前
经典MUSIC算法程序以及测角精度与阵元间距、阵元数、信噪比、快拍数等的关系
算法
十八岁讨厌编程21 分钟前
【算法训练营 · 补充】LeetCode Hot100(下)
算法·leetcode·职场和发展
一路往蓝-Anbo28 分钟前
C语言从句柄到对象 (三) —— 抛弃 Malloc:静态对象池与索引句柄的终极形态
c语言·开发语言·数据结构·stm32·单片机·算法
fantasy_arch1 小时前
SVT-AV1 B帧决策和mini-GOP决策分析
算法·av1
声声codeGrandMaster1 小时前
逻辑回归-泰坦尼克号
算法·机器学习·逻辑回归
mu_guang_2 小时前
算法图解2-选择排序
数据结构·算法·排序算法
xiaowu0802 小时前
IEnumerable、IEnumerator接口与yield return关键字的相关知识
java·开发语言·算法
报错小能手2 小时前
数据结构 b+树
数据结构·b树·算法
元亓亓亓2 小时前
LeetCode热题100--64. 最小路径和--中等
算法·leetcode·职场和发展
mit6.8242 小时前
回溯+位运算|前缀和优化背包
算法