leetcode925 Long Pressed Name

给定字符串 A 和 B ,输入 A 时某些字母会手抖打多遍,问 B 是否可能是 A 手抖后的结果。

思路:暴力即可,两个指针,满足不了条件就return false

class Solution {
public:
    bool isLongPressedName(string name, string typed) {
        int i=0,j=0;
        int len1=name.length(),len2=typed.length();
        if(len1>len2) return false;
        while(i<len1||j<len2)
        { 
            if(name[i]==typed[j]){
                i++,j++;
            }
            else if(name[i-1]==typed[j])
            {
                j++;
            }
            else 
            {
                return false;
            }
        }
        return true;
    }
};

猜你喜欢

转载自blog.csdn.net/qq_41156122/article/details/83351578