LeetCode solutions

1933. Number of Different Integers in a String

My accepted Python solution to LeetCode problem 1933, Number of Different Integers in a String, running in 0ms.

  • Difficulty: Easy
  • Python
  • Runtime 0ms
  • Memory 17.2MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.2MB, accepted 2025-12-30.

python
class Solution:
    def numDifferentIntegers(self, word: str) -> int:
        # Replace non-digits with spaces and split
        modified = ''
        for c in word:
            if c.isdigit():
                modified += c
            else:
                modified += ' '
        # Split and remove leading zeros
        integers = set()
        for part in modified.split():
            integers.add(int(part))  # int removes leading zeros
        return len(integers)

Source