Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does leetcode implement a pattern with at least K repeats and M length

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how leetcode can achieve a mode with at least K repeats and M length. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

Give you an array of positive integers arr, please find a pattern of length m and repeat at least k times in the array.

A pattern is a subarray of one or more values (a continuous subsequence) that is repeated many times in a row but does not overlap. The pattern is defined by its length and the number of repeats.

If there is a pattern in the array that is repeated at least k times and of length m, true is returned, otherwise false is returned.

Example 1:

Input: arr = [1, 2, 4, 4, 4], m = 1, k = 3

Output: true

Explanation: the length of pattern (4) is 1 and is repeated 4 times in a row. Note that the pattern can be repeated k or more times, but not less than k times.

Example 2:

Input: arr = [1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 3], m = 2, k = 2

Output: true

Explanation: the length of the pattern (1) is 2, and it is repeated 2 times in a row. Another pattern that conforms to the meaning of the question is (2), which is repeated twice as well.

Example 3:

Input: arr = [1, 2, 1, 2, 1, 3], m = 2, k = 3

Output: false

Explanation: the length of the pattern (1) is 2, but it is only repeated twice in a row. There is no pattern of length 2 and at least 3 repeats.

Example 4:

Input: arr = [1, 2, 3, 1, 2], m = 2, k = 2

Output: false

Explanation: the pattern (1) appears twice but is not continuous, so it cannot be counted as 2 consecutive repeats.

Example 5:

Input: arr = [2jue 2jin2], m = 2, k = 3

Output: false

Explanation: the pattern of length 2 is only (2), but it is only repeated twice in a row. Note that the number of repetitions of overlap cannot be calculated.

Tip:

two

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report