刷题记录: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;
    }
};
相关推荐
孤飞4 小时前
zero2Agent:面向大厂面试的 Agent 工程教程,从概念到生产的完整学习路线
算法
lclin_20204 小时前
VS2010兼容|C++系统全能监控工具(彩色界面+日志带单位+完整版)
c++·windows·系统监控·vs2010·编程实战
技术专家5 小时前
Stable Diffusion系列的详细讨论 / Detailed Discussion of the Stable Diffusion Series
人工智能·python·算法·推荐算法·1024程序员节
csdn_aspnet5 小时前
C# (QuickSort using Random Pivoting)使用随机枢轴的快速排序
数据结构·算法·c#·排序算法
以神为界5 小时前
Python入门实操:基础语法+爬虫入门+模块使用全指南
开发语言·网络·爬虫·python·安全·web
鹿角片ljp5 小时前
最长回文子串(LeetCode 5)详解
算法·leetcode·职场和发展
逻辑驱动的ken6 小时前
Java高频面试题:03
java·开发语言·面试·求职招聘·春招
噜噜大王_6 小时前
深入理解 C 语言内存操作函数:memcpy、memmove、memset、memcmp
c语言·开发语言
广师大-Wzx6 小时前
一篇文章看懂MySQL数据库(下)
java·开发语言·数据结构·数据库·windows·python·mysql
野生技术架构师6 小时前
Java NIO到底是个什么东西?
java·开发语言·nio