LeetCode-925.长按键入

it2025-03-17  12

题目: 代码:

class Solution { public: bool isLongPressedName(string name, string typed) { int m=name.size(),n=typed.size(); int i=0,j=0,count1=0,count2=0; bool ans; while(i<m&&j<n){ if(name[i]!=typed[j]) return false; for(count1=1;i+count1<m;count1++){ if(name[i]!=name[i+count1]) break; } for(count2=1;j+count2<n;count2++){ if(typed[j]!=typed[j+count2]) break; } if(count2<count1) return false; i+=count1; j+=count2; } if(i==m&&j==n) return true; return false; } };

思路:双指针,统计每个字符连续出现的次数

最新回复(0)