[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
answers.append(int(number))
else:
i += 1
return len(set(answers))

--

--

--

Learning, and posting my findings!

Love podcasts or audiobooks? Learn on the go with our new app.

Jitter #6 | Computer Vision with cv.jit Part 1

Magento 2 Amasty Facebook Comments module — Technical Review and Rating

Oracle Customers can now seamlessly use the Snowflake Data Cloud

Query only Alpha Numeric values in SOQL

Depth-First Search, without Recursion

*Custom Jenkins Image Automation With Dockerfile*

Comparison of Web Framework-Spring and Echo

What You Need to Know about Containers in 2018

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!

More from Medium

All Possible Full Binary Trees Solution | LeetCode-894: Medium | JavaScript Implementation

Sliding Window Algorithm

Leetcode 8. String to Integer (atoi)

Linked List: The Complete Guide to Linked Lists, Their Uses and What You Need to Know

Linked List