-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1551.minimum-operations-to-make-array-equal.py
More file actions
45 lines (36 loc) · 1.19 KB
/
1551.minimum-operations-to-make-array-equal.py
File metadata and controls
45 lines (36 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class Solution:
def minOperations(self, n: int) -> int:
# if n % 2 != 0:
midelement = 2 * (n//2) + 1
x = 0
y = n-1
result = 0
for i in range(n//2):
xval = 2*x+1
yval = 2*y+1
if xval < midelement:
# print("x =", x)
result += abs(xval-midelement)
x += 1
if yval > midelement:
# print(" y = ", y)
result += abs(yval-midelement)
y = y - 1
return (result // 2)
# else:
# midelement = 2 * (n//2) + 1
# midelement2 = 2 * ((n//2)-1) + 1
# x = 0
# y = n-1
# result = 0
# result2 = 0
# for i in range(n//2):
# x = 2*x+1
# y = 2*y+1
# if x < midelement:
# result += abs(x-midelement)
# x += 1
# if y > midelement:
# result += abs(y-midelement)
# y -= 1
# return result // 2