You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/2500-2599/2502.Design Memory Allocator/README_EN.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -42,15 +42,15 @@ tags:
42
42
<ul>
43
43
<li><code>Allocator(int n)</code> Initializes an <code>Allocator</code> object with a memory array of size <code>n</code>.</li>
44
44
<li><code>int allocate(int size, int mID)</code> Find the <strong>leftmost</strong> block of <code>size</code> <strong>consecutive</strong> free memory units and allocate it with the id <code>mID</code>. Return the block's first index. If such a block does not exist, return <code>-1</code>.</li>
45
-
<li><code>int free(int mID)</code> Free all memory units with the id <code>mID</code>. Return the number of memory units you have freed.</li>
45
+
<li><code>int freeMemory(int mID)</code> Free all memory units with the id <code>mID</code>. Return the number of memory units you have freed.</li>
@@ -60,21 +60,21 @@ Allocator loc = new Allocator(10); // Initialize a memory array of size 10. All
60
60
loc.allocate(1, 1); // The leftmost block's first index is 0. The memory array becomes [<strong>1</strong>,_,_,_,_,_,_,_,_,_]. We return 0.
61
61
loc.allocate(1, 2); // The leftmost block's first index is 1. The memory array becomes [1,<strong>2</strong>,_,_,_,_,_,_,_,_]. We return 1.
62
62
loc.allocate(1, 3); // The leftmost block's first index is 2. The memory array becomes [1,2,<strong>3</strong>,_,_,_,_,_,_,_]. We return 2.
63
-
loc.free(2); // Free all memory units with mID 2. The memory array becomes [1,_, 3,_,_,_,_,_,_,_]. We return 1 since there is only 1 unit with mID 2.
63
+
loc.freeMemory(2); // Free all memory units with mID 2. The memory array becomes [1,_, 3,_,_,_,_,_,_,_]. We return 1 since there is only 1 unit with mID 2.
64
64
loc.allocate(3, 4); // The leftmost block's first index is 3. The memory array becomes [1,_,3,<strong>4</strong>,<strong>4</strong>,<strong>4</strong>,_,_,_,_]. We return 3.
65
65
loc.allocate(1, 1); // The leftmost block's first index is 1. The memory array becomes [1,<strong>1</strong>,3,4,4,4,_,_,_,_]. We return 1.
66
66
loc.allocate(1, 1); // The leftmost block's first index is 6. The memory array becomes [1,1,3,4,4,4,<strong>1</strong>,_,_,_]. We return 6.
67
-
loc.free(1); // Free all memory units with mID 1. The memory array becomes [_,_,3,4,4,4,_,_,_,_]. We return 3 since there are 3 units with mID 1.
67
+
loc.freeMemory(1); // Free all memory units with mID 1. The memory array becomes [_,_,3,4,4,4,_,_,_,_]. We return 3 since there are 3 units with mID 1.
68
68
loc.allocate(10, 2); // We can not find any free block with 10 consecutive free memory units, so we return -1.
69
-
loc.free(7); // Free all memory units with mID 7. The memory array remains the same since there is no memory unit with mID 7. We return 0.
69
+
loc.freeMemory(7); // Free all memory units with mID 7. The memory array remains the same since there is no memory unit with mID 7. We return 0.
70
70
</pre>
71
71
72
72
<p> </p>
73
73
<p><strong>Constraints:</strong></p>
74
74
75
75
<ul>
76
76
<li><code>1 <= n, size, mID <= 1000</code></li>
77
-
<li>At most <code>1000</code> calls will be made to <code>allocate</code> and <code>free</code>.</li>
77
+
<li>At most <code>1000</code> calls will be made to <code>allocate</code> and <code>freeMemory</code>.</li>
0 commit comments