leetcode

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 64e93c0e587baae258cf641bc8c7f40d205cc405
parent 43f16f4cfb3ae2f791144ad7b6d4bc9bf05f3f8b
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date:   Sat, 10 Jun 2023 21:35:29 -0500

Completed snapshot array using dart

Diffstat:
Asnapshot-array/snapshot-array.dart | 26++++++++++++++++++++++++++
1 file changed, 26 insertions(+), 0 deletions(-)

diff --git a/snapshot-array/snapshot-array.dart b/snapshot-array/snapshot-array.dart @@ -0,0 +1,26 @@ +//Create a class that implements the following interface: + +//Ability to create list of length length +//Ability to set a given index to a certain val +//Ability to take a snapshot of the current list. +//Ability to get a given index of a given snapshot. + +class SnapshotArray { + List<List<int>> lists = []; + SnapshotArray(int length) { + lists.add(List.filled(length , 0)); + } + + void set(int index, int val) { + lists[lists.length - 1][index] = val; + } + + int snap() { + lists.add(List.from(lists[lists.length - 1])); + return lists.length - 2; + } + + int get(int index, int snap_id) { + return (lists[snap_id][index]); + } +}