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;
    }
};
相关推荐
Indigo_code1 小时前
【数据结构】【顺序表算法】 删除特定值
数据结构·算法
阿史大杯茶2 小时前
Codeforces Round 976 (Div. 2 ABCDE题)视频讲解
数据结构·c++·算法
LluckyYH2 小时前
代码随想录Day 58|拓扑排序、dijkstra算法精讲,题目:软件构建、参加科学大会
算法·深度优先·动态规划·软件构建·图论·dfs
转调2 小时前
每日一练:地下城游戏
开发语言·c++·算法·leetcode
不穿格子衬衫3 小时前
常用排序算法(下)
c语言·开发语言·数据结构·算法·排序算法·八大排序
wdxylb3 小时前
使用C++的OpenSSL 库实现 AES 加密和解密文件
开发语言·c++·算法
aqua35357423583 小时前
蓝桥杯-财务管理
java·c语言·数据结构·算法
CV金科3 小时前
蓝桥杯—STM32G431RBT6(IIC通信--EEPROM(AT24C02)存储器进行通信)
stm32·单片机·嵌入式硬件·算法·蓝桥杯
sewinger3 小时前
区间合并算法详解
算法
XY.散人4 小时前
初识算法 · 滑动窗口(1)
算法