mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-06 16:01:41 +08:00
存量题库数据更新
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
<p>Implement a SnapshotArray that supports the following interface:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>SnapshotArray(int length)</code> initializes an array-like data structure with the given length. <strong>Initially, each element equals 0</strong>.</li>
|
||||
<li><code>SnapshotArray(int length)</code> initializes an array-like data structure with the given length. <strong>Initially, each element equals 0</strong>.</li>
|
||||
<li><code>void set(index, val)</code> sets the element at the given <code>index</code> to be equal to <code>val</code>.</li>
|
||||
<li><code>int snap()</code> takes a snapshot of the array and returns the <code>snap_id</code>: the total number of times we called <code>snap()</code> minus <code>1</code>.</li>
|
||||
<li><code>int get(index, snap_id)</code> returns the value at the given <code>index</code>, at the time we took the snapshot with the given <code>snap_id</code></li>
|
||||
<li><code>int snap()</code> takes a snapshot of the array and returns the <code>snap_id</code>: the total number of times we called <code>snap()</code> minus <code>1</code>.</li>
|
||||
<li><code>int get(index, snap_id)</code> returns the value at the given <code>index</code>, at the time we took the snapshot with the given <code>snap_id</code></li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> ["SnapshotArray","set","snap","set","get"]
|
||||
@@ -25,9 +25,9 @@ snapshotArr.get(0,0); // Get the value of array[0] with snap_id = 0, return 5</
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= length <= 50000</code></li>
|
||||
<li>At most <code>50000</code> calls will be made to <code>set</code>, <code>snap</code>, and <code>get</code>.</li>
|
||||
<li><code>0 <= index < length</code></li>
|
||||
<li><code>0 <= snap_id < </code>(the total number of times we call <code>snap()</code>)</li>
|
||||
<li><code>0 <= val <= 10^9</code></li>
|
||||
<li><code>1 <= length <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>0 <= index < length</code></li>
|
||||
<li><code>0 <= val <= 10<sup>9</sup></code></li>
|
||||
<li><code>0 <= snap_id < </code>(the total number of times we call <code>snap()</code>)</li>
|
||||
<li>At most <code>5 * 10<sup>4</sup></code> calls will be made to <code>set</code>, <code>snap</code>, and <code>get</code>.</li>
|
||||
</ul>
|
||||
|
Reference in New Issue
Block a user