-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add two tasks for practicum backend test work
- Loading branch information
Showing
3 changed files
with
73 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
""" | ||
ПРИНЦИП РАБОТЫ | ||
Используем указатель и перезапишем массив, исключая все нули. | ||
ВРЕМЕННАЯ СЛОЖНОСТЬ | ||
O(n), где n - количество элементов в массиве. | ||
ПРОСТРАНСТВЕННАЯ СЛОЖНОСТЬ | ||
O(1) | ||
""" | ||
|
||
|
||
def delete_zero(arr): | ||
zeros = 0 | ||
|
||
for item in arr: | ||
if item != 0: | ||
arr[zeros] = item | ||
zeros += 1 | ||
|
||
return arr[:zeros] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
ПРИНЦИП РАБОТЫ | ||
Используем хеш-таблицу. Сохраняем все элементы второго массива в хэш-таблице. | ||
Один за другим проверяем все элементы первого массива и выводим все элементы, которых нет в хэш-таблице. | ||
ВРЕМЕННАЯ СЛОЖНОСТЬ | ||
O(n + m), где n, m - количество элементов в первом и во втором списках соответственно. | ||
ПРОСТРАНСТВЕННАЯ СЛОЖНОСТЬ | ||
O(n + m), где n, m - количество элементов в первом и во втором списках соответственно. | ||
""" | ||
|
||
|
||
def find_missing(first, second): | ||
hash_table = {item: 1 for item in second} | ||
return [item for item in first if item not in hash_table.keys()] |