This is kind of a beginner's question but the code I am looking at is in production and I don't want to break anything. So, just in case: isn't
text.Substring(index, length).Length
is equivalent to just length
?
(Except for the potential ArgumentOutOfRangeException.)
Approach: The count of sub-strings of length n will always be len – n + 1 where len is the length of the given string.
If the length of a string is N, then there can be N – K + 1 substring of length K. Generating these substrings will require O(N) complexity, and checking each substring requires O(K) complexity, hence making the overall complexity like O(N*K). Efficient approach: The idea is to use Window Sliding Technique.
Alternatively referred to as substr, a substring is a prefix or suffix of any string. For example, a substring of the word "computer" could be: puter or comp.
Yes, it will be exactly the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With