Skip to content

Latest commit

 

History

History
27 lines (23 loc) · 633 Bytes

Question_1668.md

File metadata and controls

27 lines (23 loc) · 633 Bytes

LeetCode Records - Question 1668 Maximum Repeating Substring

Attempt 1: Use contains() to check the repeated words

class Solution {
    public int maxRepeating(String sequence, String word) {
        String target = word;
        int maxTime = sequence.length() / word.length();

        int i = 0;
        while (i < maxTime) {
            if (sequence.contains(target)) {
                target += word;
                i++;
            } else {
                break;
            }
        }

        return i;
    }
}
  • Runtime: 1 ms (Beats: 57.52%)
  • Memory: 41.66 MB (Beats: 44.54%)