Trie-Trie-Trie!!! - Part 5
An interesting problem that can be solved with Tries (there are other solutions too). You can create a simple trie and add all the digits to it. Then the idea is to have a Search function that given the original string and the current index, searches for any match in the trie starting at that index, and if there is a match, returns the jump offset. Complexity becomes the length of the string times the depth of the trie, which is a constant, hence the final time complexity is linear. Code is down below, cheers, ACC. Convert Number Words to Digits - LeetCode You are given a string s consisting of lowercase English letters. s may contain valid concatenated English words representing the digits 0 to 9, without spaces. Your task is to extract each valid number word in order and convert it to its corresponding digit, producing a string of digits. Parse s from left to right. At each position: If a valid number word s...