java.lang.Object
g2201_2300.s2269_find_the_k_beauty_of_a_number.Solution

public class Solution extends Object
2269 - Find the K-Beauty of a Number.<p>Easy</p> <p>The <strong>k-beauty</strong> of an integer <code>num</code> is defined as the number of <strong>substrings</strong> of <code>num</code> when it is read as a string that meet the following conditions:</p> <ul> <li>It has a length of <code>k</code>.</li> <li>It is a divisor of <code>num</code>.</li> </ul> <p>Given integers <code>num</code> and <code>k</code>, return <em>the k-beauty of</em> <code>num</code>.</p> <p>Note:</p> <ul> <li><strong>Leading zeros</strong> are allowed.</li> <li><code>0</code> is not a divisor of any value.</li> </ul> <p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> num = 240, k = 2</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> The following are the substrings of num of length k:</p> <ul> <li> <p>&ldquo;24&rdquo; from &ldquo;<strong>24</strong>0&rdquo;: 24 is a divisor of 240.</p> </li> <li> <p>&ldquo;40&rdquo; from &ldquo;2<strong>40</strong>&rdquo;: 40 is a divisor of 240.</p> </li> </ul> <p>Therefore, the k-beauty is 2.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> num = 430043, k = 2</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> The following are the substrings of num of length k:</p> <ul> <li> <p>&ldquo;43&rdquo; from &ldquo;<strong>43</strong>0043&rdquo;: 43 is a divisor of 430043.</p> </li> <li> <p>&ldquo;30&rdquo; from &ldquo;4<strong>30</strong>043&rdquo;: 30 is not a divisor of 430043.</p> </li> <li> <p>&ldquo;00&rdquo; from &ldquo;43<strong>00</strong>43&rdquo;: 0 is not a divisor of 430043.</p> </li> <li> <p>&ldquo;04&rdquo; from &ldquo;430<strong>04</strong>3&rdquo;: 4 is not a divisor of 430043.</p> </li> <li> <p>&ldquo;43&rdquo; from &ldquo;4300<strong>43</strong>&rdquo;: 43 is a divisor of 430043.</p> </li> </ul> <p>Therefore, the k-beauty is 2.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= num <= 10<sup>9</sup></code></li> <li><code>1 <= k <= num.length</code> (taking <code>num</code> as a string)</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • divisorSubstrings

      public int divisorSubstrings(int num, int k)