for(int i = 0;i < length; i++){
count[string[i] - 'a']++;
}
I have seen many people use this code to count the number of occurrences of each letter in a string.Would like to know how this code does that.
for(int i = 0;i < length; i++){
count[string[i] - 'a']++;
}
I have seen many people use this code to count the number of occurrences of each letter in a string.Would like to know how this code does that.
Every char is a number in C++. So count[i] stores the number of occurences of i'th letter.