登 录
一、时间复杂度是O(N). #include <stdio.h> int arr[3] = {0, 0, 0}; enum {a, b, c}; /* hash function : f(key) = key - 'a' */ int main() { char *s = "aabbbbcccccccccc"; int i;
while(*s != '/0'){ arr[*s - 'a']++; s++; } for(i = 0; i < 3; i++){ printf("%d ", arr[i]); } return 0; }
抱歉!评论已关闭.