java.lang.Object
g1801_1900.s1805_number_of_different_integers_in_a_string.Solution

public class Solution extends Object
1805 - Number of Different Integers in a String.<p>Easy</p> <p>You are given a string <code>word</code> that consists of digits and lowercase English letters.</p> <p>You will replace every non-digit character with a space. For example, <code>&quot;a123bc34d8ef34&quot;</code> will become <code>&quot; 123 34 8 34&quot;</code>. Notice that you are left with some integers that are separated by at least one space: <code>&quot;123&quot;</code>, <code>&quot;34&quot;</code>, <code>&quot;8&quot;</code>, and <code>&quot;34&quot;</code>.</p> <p>Return <em>the number of <strong>different</strong> integers after performing the replacement operations on</em> <code>word</code>.</p> <p>Two integers are considered different if their decimal representations <strong>without any leading zeros</strong> are different.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> word = &ldquo;a123bc34d8ef34&rdquo;</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> The three different integers are &ldquo;123&rdquo;, &ldquo;34&rdquo;, and &ldquo;8&rdquo;. Notice that &ldquo;34&rdquo; is only counted once.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> word = &ldquo;leet1234code234&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> word = &ldquo;a1b01c001&rdquo;</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> The three integers &ldquo;1&rdquo;, &ldquo;01&rdquo;, and &ldquo;001&rdquo; all represent the same integer because the leading zeros are ignored when comparing their decimal values.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= word.length <= 1000</code></li> <li><code>word</code> consists of digits and lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • numDifferentIntegers

      public int numDifferentIntegers(String word)