刷题记录: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;
    }
};

相关推荐

  1. 记录LeetCode 925.按键

    2024-07-17 23:02:02       22 阅读
  2. LeetCode记录——day7

    2024-07-17 23:02:02       36 阅读
  3. LeetCode记录——day8

    2024-07-17 23:02:02       37 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-17 23:02:02       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-17 23:02:02       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-17 23:02:02       58 阅读
  4. Python语言-面向对象

    2024-07-17 23:02:02       69 阅读

热门阅读

  1. 实际项目中JVM调优

    2024-07-17 23:02:02       17 阅读
  2. 如何做到思维的顺畅运行

    2024-07-17 23:02:02       20 阅读
  3. Linux下Supervisor的安装与配置

    2024-07-17 23:02:02       18 阅读
  4. 布儒斯特定律

    2024-07-17 23:02:02       17 阅读
  5. A const member function

    2024-07-17 23:02:02       22 阅读
  6. 代码随想录算法训练营第14天/优先掌握递归

    2024-07-17 23:02:02       24 阅读
  7. ES6函数部分和数组部分的小练习

    2024-07-17 23:02:02       20 阅读
  8. 学习笔记(数据库)1

    2024-07-17 23:02:02       17 阅读
  9. 后端实现图片上传本地,可采用url查看图片

    2024-07-17 23:02:02       22 阅读