若是兄弟,则str1和str2必须最少遍历一遍;若不是兄弟,则可以提前终止遍历。
int func(char *str1, char *str2) { // ASCII nums int i, j, count[128]; char *p1, *p2; p1 = str1; p2 = str2; j = 0; // initial array for(i=0; i<128; i++) count[i] = 0; while('\0' != *p1) { count[*p1++]++; j++; } while('\0' != *p2) { count[*p2]--; j--; if(j < 0 || count[*p2] < 0) return 0; p2++; } // check 0 for(i=0; i<128; i++) { if(count[i] != 0) return 0; } return 1; }