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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 17.2MB, accepted 2025-12-30.
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)