파비의 매일매일 공부기록

2023.06.11 Today's Challenge 본문

Problem Solving/LeetCode

2023.06.11 Today's Challenge

fabichoi 2023. 6. 11. 23:45

https://leetcode.com/problems/snapshot-array/

그리 어렵지는 않았던 문제

class SnapshotArray:
    def __init__(self, length: int):
        self.id = 0
        self.history_records = [[[0, 0]] for _ in range(length)]

    def set(self, index: int, val: int) -> None:
        self.history_records[index].append([self.id, val])
        
    def snap(self) -> int:
        self.id += 1
        return self.id - 1

    def get(self, index: int, snap_id: int) -> int:
        snap_index = bisect.bisect_right(self.history_records[index], [snap_id, 10**9])
        return self.history_records[index][snap_index-1][1]
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

2023.06.13 Today's Challenge  (0) 2023.06.13
2023.06.12 Today's Challenge  (0) 2023.06.12
2023.06.10 Today's Challenge  (0) 2023.06.10
2023.06.09 Today's Challenge  (0) 2023.06.09
2023.06.08 Today's Challenge  (0) 2023.06.08
Comments