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;
    }
};
相关推荐
朝朝又沐沐1 小时前
算法竞赛阶段二-数据结构(36)数据结构双向链表模拟实现
开发语言·数据结构·c++·算法·链表
薰衣草23332 小时前
一天两道力扣(6)
算法·leetcode
剪一朵云爱着2 小时前
力扣946. 验证栈序列
算法·
遇见尚硅谷2 小时前
C语言:*p++与p++有何区别
c语言·开发语言·笔记·学习·算法
天天开心(∩_∩)3 小时前
代码随想录算法训练营第三十二天
算法
YouQian7723 小时前
(AC)缓存系统
算法·缓存
艾莉丝努力练剑3 小时前
【数据结构与算法】数据结构初阶:详解排序(二)——交换排序中的快速排序
c语言·开发语言·数据结构·学习·算法·链表·排序算法
科大饭桶3 小时前
数据结构自学Day13 -- 快速排序--“前后指针法”
数据结构·算法·leetcode·排序算法·c
李永奉3 小时前
C语言-流程控制语句:for循环语句、while和do…while循环语句;
c语言·开发语言·c++·算法
程序员-King.3 小时前
day69—动态规划—爬楼梯(LeetCode-70)
算法·动态规划