Strings in C are always terminated by the '\0' character. We can explore this to avoid sweeping through the string twice.
Constructs like for (i = 0; i < strlen(str); i++) are even worse than this, as it will call strlen for each character of the string, which is O(n ²) instead of O(n), where n = size of string. Replace those cases as well.
Strings in C are always terminated by the '\0' character. We can explore this to avoid sweeping through the string twice.
Constructs like
for (i = 0; i < strlen(str); i++)
are even worse than this, as it will call strlen for each character of the string, which is O(n ²) instead of O(n), where n = size of string. Replace those cases as well.