leetcode 1153 has insufficient test cases to allow wrong solution to accept.
My following code
#define NUM 10005
#define LEN 27
int p1[NUM], p2[NUM], cnt[LEN];
static inline int
proc(char *s, int *p, int *c)
{
int i, l, n = 0;
l = strlen(s);
p[0] = 1;
for(i=1; i<l; i++) {
if (s[i] == s[i-1]) {
p[n]++;
}else {
n++;
p[n] = 1;
}
}
memset(cnt, 0, sizeof(cnt));
for(i=0; i<l; i++) cnt[s[i]-'a']++;
for(*c=0, i=0; i<LEN; i++) if (cnt[i]) *c += 1;
return n+1;
}
bool canConvert(char * str1, char * str2){
int i, n1, n2, j, c1, c2;
if (!strcmp(str1, str2)) return true;
n1 = proc(str1, p1, &c1);
n2 = proc(str2, p2, &c2);
if (c1 == 26 && c1 == c2) return false;
i = j = 0;
while (j<n2) {
if (p1[i]>p2[j]) return false;
else if (p1[i] == p2[j]) {
i++;
j++;
} else {
p2[j] -= p1[i];
i++;
}
}
return true;
}gives wrong answer to test case
"aabaa"
"ccdee"
but, it is Accepted.