How to check for repeating sequence in an integer

后端 未结 5 1685
夕颜
夕颜 2021-01-31 18:15

I have an alpha-numeric string and I want to check for pattern repetition in it just for the integers. And they should be continuous.

Example

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-31 19:10

    First you'd want to define some rules for a pattern. If a pattern could have any arbitrary length, then you should start storing int values (building up the pattern) and starting to check for a repetition at the first repeated int.

    In this case: 1234123q You're building the 1234 pattern, then since 1 is repeated you should keep storing it AND start comparing it with the next values.

    How do you handle repetitions inside a pattern?

    In the case: 123124123124

    the pattern 123124 is repeated twice. Should it register as a repetition, or stop at the the first 4 since 123 != 124 ?

    If you choose to register those case as valid repetition, you'll need to start creating parallel patterns to check at the sime times as you keep building them up.

    The firs case (stopping at the first NOT repeated value) is simple, the second case will generate a lot of parralel patterns to build and to check at the same time.

    Once you reach the end of the stream you could do the search using String-provided existing methods.

提交回复
热议问题