# LeetCode - 0925. Long Pressed Name ### 題目網址:https://leetcode.com/problems/long-pressed-name/ ###### tags: `LeetCode` `Easy` `字串` ```cpp= /* -LeetCode format- Problem: 925. Long Pressed Name Difficulty: Easy by Inversionpeter */ class Solution { public: bool isLongPressedName(string name, string typed) { if (name[0] != typed[0]) return false; int first = 1, second = 1; while (first != name.size()) { if (second == typed.size() || name[first] != typed[second]) { while (second != typed.size() && typed[second - 1] == typed[second]) ++second; if (second == typed.size() || name[first] != typed[second]) return false; } ++first; ++second; } while (second != typed.size() && typed[second - 1] == typed[second]) ++second; return second == typed.size(); } }; ```