Skip to content

Commit

Permalink
Create SolutionByDhaval.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dhavalpandey authored Oct 30, 2023
1 parent b7cbc6c commit 4537203
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
arr_in = input()[9:]
arr_in = arr_in[:-1]

arr_in = arr_in.replace(" ", "")
arr = list(map(int, arr_in.split(",")))

target_num = input().replace(" ", "")
num = int(target_num.split("=")[1])

smallest_diff = abs(arr[0]-num)
closest_num = 0

for index in arr:
diff = abs(index-num)
if diff < smallest_diff:
smallest_diff = diff
closest_num = index

print(closest_num)

0 comments on commit 4537203

Please sign in to comment.