How to find repeating sequence of Integers in an array of Integers?

后端 未结 4 1254
清酒与你
清酒与你 2021-01-07 14:52

How to find repeating sequence of Integers in an array of Integers?

00 would be repeating, so would 123123, but 01234593623 would not be.

I have an idea to h

4条回答
  •  旧时难觅i
    2021-01-07 15:22

    You can always play with regular expressions to achieve a desired result. Use the regex backreference and combine it with the greedy quantifier:

        void printRepeating(String arrayOfInt)
        {
            String regex = "(\\d+)\\1";
            Pattern patt = Pattern.compile(regex);
            Matcher matcher = patt.matcher(arrayOfInt);           
            while (matcher.find())                              
            {               
                System.out.println("Repeated substring: " + matcher.group(1));
            } 
        }          
    

提交回复
热议问题