package leetcode;

public class Problem1146 {
}

@@ -16,33 +16,1546 @@
 e;%0A%0A
-public class Problem1146 %7B
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A/**%0A * https://leetcode.com/problems/snapshot-array/%0A */%0Apublic class Problem1146 %7B%0A    private static class SnapshotArray %7B%0A        private final int length;%0A        private int snapshot;%0A        private final Map%3C/*snapshot ID*/ Integer, int%5B%5D%3E snapshots = new HashMap%3C%3E();%0A%0A        public SnapshotArray(int length) %7B%0A            this.length = length;%0A        %7D%0A%0A        public void set(int index, int val) %7B%0A            if (!snapshots.containsKey(snapshot)) %7B%0A                snapshots.put(snapshot, new int%5Blength%5D);%0A            %7D%0A            snapshots.get(snapshot)%5Bindex%5D = val;%0A        %7D%0A%0A        public int snap() %7B%0A            return snapshot++;%0A        %7D%0A%0A        public int get(int index, int snap_id) %7B%0A            if (!snapshots.containsKey(snap_id)) %7B%0A                return 0;%0A            %7D%0A            return snapshots.get(snap_id)%5Bindex%5D;%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        SnapshotArray sa = new SnapshotArray(3);%0A//        sa.set(0, 5);%0A//        System.out.println(sa.snap()); // 0%0A//        sa.set(0, 6);%0A//        System.out.println(sa.get(0, 0)); // 5%0A%0A        sa = new SnapshotArray(1);%0A        sa.set(0, 15);%0A        System.out.println(sa.snap()); // 0%0A        System.out.println(sa.snap()); // 1%0A        System.out.println(sa.snap()); // 2%0A        System.out.println(sa.get(0, 2)); // 15%0A        System.out.println(sa.snap()); // 3%0A        System.out.println(sa.snap()); // 4%0A        System.out.println(sa.get(0, 0)); // 15%0A    %7D
 %0A%7D%0A

Update problem 1146