013 Three Div Sequences

Tech In Pieces發表於2020-12-22

we are given a string called number, which represents an integer.
now we need to get the number of substrings that can be divisible by 3.
pay attention: the substring must can’t have leading zero unless it’s just zero.

of course we can do this in brute force way:
get every substrings of given string, check if it is valid.
then for every valid, parse it into int, and check if it is divisible by 3.

相關文章