题目: 代码:
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;
}
};
思路:双指针,统计每个字符连续出现的次数
转载请注明原文地址: https://lol.8miu.com/read-23887.html