[Leet Code] Number of Different Integers in a String

Input: word = "a123bc34d8ef34"
Output: 3
Explanation: The three different integers are "123", "34", and "8". Notice that "34" is only counted once.
Input: word = "leet1234code234"
Output: 2
Input: word = "a1b01c001"
Output: 1
Explanation: The three integers "1", "01", and "001" all represent the same integer because
the leading zeros are ignored when comparing their decimal values.
class Solution(object):
def numDifferentIntegers(self, word):
:type word: str
:rtype: int
answers = []
lengthOfWord = len(word)
i = 0
while i < lengthOfWord:
if word[i].isnumeric():
number = ""
while i < lengthOfWord and word[i].isnumeric():
number += word[i]
i += 1
i += 1
return len(set(answers))



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Matthew Boyd

Matthew Boyd

Learning, and posting my findings!