I want to create a function that returns true if a number has consecutive digits or not,
example:
- if the input is 11, it will return true
- if the input is 21 it will return false
- if the input is 323 it will return false because even though we have 3 repeated, they are not consecutive
My solution right now is to transform the number into an array and loop through the number one by one, if the next number is equal to the current number then we just return true. But this has a complexity time of O(n) and I was wondering if anyone can come with a better solution.
Thank you
O(n)for this purpose.2345674396539588934682364823553and more... I think the regex would do only 10 iterations (see my answer). So it should be faster.