Python simple solution
The thought is quite straight forward.\n\nFirst, we temporarily record the modifications made by set.\nOnce we snapshot (snap), we save the modifications in the
The thought is quite straight forward.\n\nFirst, we temporarily record the modifications made by `set`.\nOnce we snapshot (`snap`), we save the modifications in the snapshots array and remove our temporary record.\n\nTo get the required value (`get`), we look into the specified snapshot first.\nIf we could not find it, we look backward to get the latest modification of the required value.\n\nIn one word, we use time (looking backward) to save space.\n\n\n```\nclass SnapshotArray:\n\n    def __init__(self, length: int):\n        self._snaps = []\n        self._set = {}\n        \n    def set(self, index: int, val: int) -> None:\n        self._set[index] = val\n\n    def snap(self) -> int:\n        self._snaps += [self._set]\n        self._set = {}\n        return len(self._snaps) - 1\n\n    def get(self, index: int, snap_id: int) -> int:\n        for i in reversed(range(snap_id + 1)):\n            if index in self._snaps[i]:\n                return self._snaps[i][index]\n        return 0\n```\n\nResult: (2019/08/04)\n- Runtime: 452 ms, faster than 100.00% of Python3 online submissions for Snapshot Array.\n- Memory Usage: 36.7 MB, less than 100.00% of Python3 online submissions for Snapshot Array.\n
[]