leetcode

Leetcode submissions
git clone git://git.laack.co/leetcode.git
Log | Files | Refs | README

snapshot-array.dart (645B)


      1 //Create a class that implements the following interface:
      2 
      3 //Ability to create list of length length
      4 //Ability to set a given index to a certain val
      5 //Ability to take a snapshot of the current list.
      6 //Ability to get a given index of a given snapshot.
      7 
      8 class SnapshotArray {
      9   List<List<int>> lists = [];
     10   SnapshotArray(int length) {
     11       lists.add(List.filled(length , 0));
     12   }
     13   
     14   void set(int index, int val) {
     15     lists[lists.length - 1][index] = val;
     16   }
     17   
     18   int snap() {
     19     lists.add(List.from(lists[lists.length - 1]));
     20     return lists.length - 2;
     21   }
     22   
     23   int get(int index, int snap_id) {
     24     return (lists[snap_id][index]);
     25   }
     26 }