刷题记录:LeetCode 925.长按键入

题目:

你的朋友正在使用键盘输入他的名字 name。偶尔,在键入字符 c 时,按键可能会被长按,而字符可能被输入 1 次或多次。

你将会检查键盘输入的字符 typed。如果它对应的可能是你的朋友的名字(其中一些字符可能被长按),那么就返回 True

复制代码
class Solution {
public:
    bool isLongPressedName(string name, string typed) {
        int nn = 0;
        int tt = 0;
        while (nn < name.size() || tt < typed.size())
        {
            if (name[nn] == typed[tt])
            {
                nn++;
                tt++;
            }
            else
            {
                if (tt == 0) return false;
                else 
                {
                    while (tt < typed.size() && typed[tt - 1] == typed[tt]) tt++;
                    if (name[nn] != typed[tt]) return false;
                    else 
                    {
                        tt++;
                        nn++;
                    }
                }
            }
        }
        if (tt < typed.size()) return false;
        return true;
    }
};
相关推荐
yue008几秒前
C# 更改窗体样式
开发语言·c#
普通网友4 分钟前
C++中的适配器模式
开发语言·c++·算法
风闲12176 分钟前
Qt源码编译记录
开发语言·qt
无敌最俊朗@22 分钟前
力扣hot100-160-相交链表
c++
普通网友27 分钟前
C++中的委托构造函数
开发语言·c++·算法
月上柳青42 分钟前
OpenWrt系统上配置batman-adv快速开始与配置详解
开发语言·mysql·php
全栈陈序员42 分钟前
基于Rust 实现的豆瓣电影 Top250 爬虫项目
开发语言·爬虫·rust
普通网友43 分钟前
C++中的代理模式实战
开发语言·c++·算法
百锦再1 小时前
第17章 模式与匹配
开发语言·后端·python·rust·django·内存·抽象
WangMing_X1 小时前
C# XML操作演示示例项目(附源码完整)
开发语言·microsoft·php