mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-23 08:51:31 -04:00
Rename check-if-exist.py to check_if_exist.py
This commit is contained in:
parent
c73adbc7b8
commit
37a25d4423
1 changed files with 0 additions and 0 deletions
|
@ -1,31 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# author: bt3gl
|
||||
|
||||
"""
|
||||
Given an array arr of integers, check if there exist two indices i and j such that :
|
||||
|
||||
i != j
|
||||
0 <= i, j < arr.length
|
||||
arr[i] == 2 * arr[j]
|
||||
"""
|
||||
|
||||
|
||||
def check_if_exist(arr: list[int]) -> bool:
|
||||
|
||||
aux_dict = {}
|
||||
|
||||
for i, num in enumerate(arr):
|
||||
aux_dict[2 * num] = i
|
||||
|
||||
for j, num in enumerate(arr):
|
||||
if num in aux_dict.keys() and j != aux_dict[num]:
|
||||
return (j, aux_dict[num])
|
||||
|
||||
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
arr = [-2, 0, 10, -19, 4, 6, -8]
|
||||
print(check_if_exist(arr))
|
Loading…
Add table
Add a link
Reference in a new issue