This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| class MyDataStructure(object): | |
| def __init__(self): | |
| self.d = {} # hash table | |
| self.li = [] # dynamic resizing array | |
| def insert(self, key): | |
| if key in self.d: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TrieNode(object): | |
| """ | |
| Trie Node | |
| """ | |
| def __init__(self,key): | |
| self._key = key | |
| self._value = None | |
| self._children = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def compress(s): | |
| """ | |
| s -> string to be compressed | |
| retuns -> compressed string | |
| """ | |
| if not s: | |
| return "" | |
| prev = None | |
| count = 0 |
OlderNewer