Skip to content

Commit bc8046e

Browse files
committed
committed from zkp
1 parent 29a9be4 commit bc8046e

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

LeetCode/build_array.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Array(object):
2+
def __init__(self, size=32):
3+
self._size = size
4+
self._items = [None] * size
5+
6+
def __getitem__(self, index):
7+
return self._items[index]
8+
9+
def __setitem__(self, index, value):
10+
self._items[index] = value
11+
12+
def __len__(self):
13+
return self._size
14+
15+
def clear(self, value=None):
16+
for i in range(len(self._items)):
17+
self._items[i] = value
18+
19+
def __iter__(self):
20+
for item in self._items:
21+
yield item
22+
23+
24+
def test_array():
25+
size = 10
26+
a = Array(size)
27+
a[0] = 1
28+
assert a[0] == 1
29+
a.clear()
30+
assert a[0] is None
31+
print("success")
32+
33+
34+
if __name__ == "__main__":
35+
test_array()

0 commit comments

Comments
 (0)