c_925_Long_Pressed_Name Posted on 2019-01-14 | In Algorithm | 1234567891011121314151617181920212223242526272829303132#include <iostream>using namespace std;class Solution {public: bool isLongPressedName(string name, string typed) { if (!name.length() && !typed.length()) { return true; } else if (!name.length() || !typed.length()) { return false; } int idx = 0; for (int i = 0; i < typed.length(); i++) { if (typed[i] == name[idx]) { idx++; } else if (idx != 0 && typed[i] == name[idx - 1]) { continue; } else { return false; } } return idx == name.length(); }};int main() { string name = "alex", typed = "aallexx"; Solution solution; bool is_pressed = solution.isLongPressedName(name, typed); cout << is_pressed << endl; return 0;}