Skip to content

Commit 26206bc

Browse files
authored
Create minimum-operations-to-make-array-equal.py
1 parent bb3caf2 commit 26206bc

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Time: O(1)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def minOperations(self, n):
6+
"""
7+
:type n: int
8+
:rtype: int
9+
"""
10+
# total = (2i+1 for i in xrange(n)) = n^2
11+
# left_half_total = (2i+1 for i in xrange(n//2)) = (n//2)^2
12+
# result = (n//2) * (total//n) - left_half_total = (n//2)*(n-n//2) = (n//2)*((n+1)//2)
13+
return (n//2)*((n+1)//2)

0 commit comments

Comments
 (0)