|
| 1 | +<h2><a href="https://leetcode.com/problems/check-if-digits-are-equal-in-string-after-operations-i">3768. Check If Digits Are Equal in String After Operations I</a></h2><h3>Easy</h3><hr><p>You are given a string <code>s</code> consisting of digits. Perform the following operation repeatedly until the string has <strong>exactly</strong> two digits:</p> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li>For each pair of consecutive digits in <code>s</code>, starting from the first digit, calculate a new digit as the sum of the two digits <strong>modulo</strong> 10.</li> |
| 5 | + <li>Replace <code>s</code> with the sequence of newly calculated digits, <em>maintaining the order</em> in which they are computed.</li> |
| 6 | +</ul> |
| 7 | + |
| 8 | +<p>Return <code>true</code> if the final two digits in <code>s</code> are the <strong>same</strong>; otherwise, return <code>false</code>.</p> |
| 9 | + |
| 10 | +<p> </p> |
| 11 | +<p><strong class="example">Example 1:</strong></p> |
| 12 | + |
| 13 | +<div class="example-block"> |
| 14 | +<p><strong>Input:</strong> <span class="example-io">s = "3902"</span></p> |
| 15 | + |
| 16 | +<p><strong>Output:</strong> <span class="example-io">true</span></p> |
| 17 | + |
| 18 | +<p><strong>Explanation:</strong></p> |
| 19 | + |
| 20 | +<ul> |
| 21 | + <li>Initially, <code>s = "3902"</code></li> |
| 22 | + <li>First operation: |
| 23 | + <ul> |
| 24 | + <li><code>(s[0] + s[1]) % 10 = (3 + 9) % 10 = 2</code></li> |
| 25 | + <li><code>(s[1] + s[2]) % 10 = (9 + 0) % 10 = 9</code></li> |
| 26 | + <li><code>(s[2] + s[3]) % 10 = (0 + 2) % 10 = 2</code></li> |
| 27 | + <li><code>s</code> becomes <code>"292"</code></li> |
| 28 | + </ul> |
| 29 | + </li> |
| 30 | + <li>Second operation: |
| 31 | + <ul> |
| 32 | + <li><code>(s[0] + s[1]) % 10 = (2 + 9) % 10 = 1</code></li> |
| 33 | + <li><code>(s[1] + s[2]) % 10 = (9 + 2) % 10 = 1</code></li> |
| 34 | + <li><code>s</code> becomes <code>"11"</code></li> |
| 35 | + </ul> |
| 36 | + </li> |
| 37 | + <li>Since the digits in <code>"11"</code> are the same, the output is <code>true</code>.</li> |
| 38 | +</ul> |
| 39 | +</div> |
| 40 | + |
| 41 | +<p><strong class="example">Example 2:</strong></p> |
| 42 | + |
| 43 | +<div class="example-block"> |
| 44 | +<p><strong>Input:</strong> <span class="example-io">s = "34789"</span></p> |
| 45 | + |
| 46 | +<p><strong>Output:</strong> <span class="example-io">false</span></p> |
| 47 | + |
| 48 | +<p><strong>Explanation:</strong></p> |
| 49 | + |
| 50 | +<ul> |
| 51 | + <li>Initially, <code>s = "34789"</code>.</li> |
| 52 | + <li>After the first operation, <code>s = "7157"</code>.</li> |
| 53 | + <li>After the second operation, <code>s = "862"</code>.</li> |
| 54 | + <li>After the third operation, <code>s = "48"</code>.</li> |
| 55 | + <li>Since <code>'4' != '8'</code>, the output is <code>false</code>.</li> |
| 56 | +</ul> |
| 57 | +</div> |
| 58 | + |
| 59 | +<p> </p> |
| 60 | +<p><strong>Constraints:</strong></p> |
| 61 | + |
| 62 | +<ul> |
| 63 | + <li><code>3 <= s.length <= 100</code></li> |
| 64 | + <li><code>s</code> consists of only digits.</li> |
| 65 | +</ul> |
0 commit comments