双指针 - 长按键入

it2024-04-19  2

题目链接

class Solution { public: bool isLongPressedName(string name, string typed) { int n1 = name.size(); int n2 = typed.size(); int i = 0, j = 0; while (j < n2) { if (i < n1 && name[i] == typed[j]) { ++i; ++j; }else if (i > 0 && name[i-1] == typed[j]) { ++j; }else { cout << i << " " << j << endl; return false; } } return i == n1; } };
最新回复(0)