|
| 1 | +<h2><a href="https://leetcode.com/problems/find-the-k-beauty-of-a-number/">2269. Find the K-Beauty of a Number</a></h2><h3>Easy</h3><hr><div><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> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li>It has a length of <code>k</code>.</li> |
| 5 | + <li>It is a divisor of <code>num</code>.</li> |
| 6 | +</ul> |
| 7 | + |
| 8 | +<p>Given integers <code>num</code> and <code>k</code>, return <em>the k-beauty of </em><code>num</code>.</p> |
| 9 | + |
| 10 | +<p>Note:</p> |
| 11 | + |
| 12 | +<ul> |
| 13 | + <li><strong>Leading zeros</strong> are allowed.</li> |
| 14 | + <li><code>0</code> is not a divisor of any value.</li> |
| 15 | +</ul> |
| 16 | + |
| 17 | +<p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p> |
| 18 | + |
| 19 | +<p> </p> |
| 20 | +<p><strong>Example 1:</strong></p> |
| 21 | + |
| 22 | +<pre><strong>Input:</strong> num = 240, k = 2 |
| 23 | +<strong>Output:</strong> 2 |
| 24 | +<strong>Explanation:</strong> The following are the substrings of num of length k: |
| 25 | +- "24" from "<strong><u>24</u></strong>0": 24 is a divisor of 240. |
| 26 | +- "40" from "2<u><strong>40</strong></u>": 40 is a divisor of 240. |
| 27 | +Therefore, the k-beauty is 2. |
| 28 | +</pre> |
| 29 | + |
| 30 | +<p><strong>Example 2:</strong></p> |
| 31 | + |
| 32 | +<pre><strong>Input:</strong> num = 430043, k = 2 |
| 33 | +<strong>Output:</strong> 2 |
| 34 | +<strong>Explanation:</strong> The following are the substrings of num of length k: |
| 35 | +- "43" from "<u><strong>43</strong></u>0043": 43 is a divisor of 430043. |
| 36 | +- "30" from "4<u><strong>30</strong></u>043": 30 is not a divisor of 430043. |
| 37 | +- "00" from "43<u><strong>00</strong></u>43": 0 is not a divisor of 430043. |
| 38 | +- "04" from "430<u><strong>04</strong></u>3": 4 is not a divisor of 430043. |
| 39 | +- "43" from "4300<u><strong>43</strong></u>": 43 is a divisor of 430043. |
| 40 | +Therefore, the k-beauty is 2. |
| 41 | +</pre> |
| 42 | + |
| 43 | +<p> </p> |
| 44 | +<p><strong>Constraints:</strong></p> |
| 45 | + |
| 46 | +<ul> |
| 47 | + <li><code>1 <= num <= 10<sup>9</sup></code></li> |
| 48 | + <li><code>1 <= k <= num.length</code> (taking <code>num</code> as a string)</li> |
| 49 | +</ul> |
| 50 | +</div> |
0 commit comments