Rename check-if-exist.py to check_if_exist.py

This commit is contained in:
marina 2023-08-07 17:23:36 -07:00 committed by GitHub
parent c73adbc7b8
commit 37a25d4423
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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))