#271 Encode and Decode Strings
Contents
Link
https://leetcode.com/problems/encode-and-decode-strings/description/
Solution
- I just used all the punctuations given by
string.punctuation
in python as the delimiter. Obvious flaw here; if the same kind of string exists in the actual string, it is going to read it as a delimiter. (It was one of those days. Tired + no motivation; but can’t miss two days in a row hehe) - To combat that, there’s an approach which is agnostic to the type of delimeter Reference
- rather it sequentially looks for a
number
followed by a special character (@). - For the next
number
of letters, it reads the string and appends it to the list. - Repeat the above steps till you reach the end of the string.
- rather it sequentially looks for a
Code
Python
|
|
Notes
- The one and only Stefan Pochmann has commented on the reference user solution. Pretty handy tip :)