- Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy patharray-ame.py
More file actions
Latest commit
23 lines (22 loc) · 641 Bytes
/
Copy patharray-ame.py
File metadata and controls
23 lines (22 loc) · 641 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fromtypingimport (
List,
)
classSolution:
"""
@param arr: the array
@return: determine the number of moves to make all elements equals
"""
defarray_game(self, arr: List[int]) ->int:
# write your code here
'''
其它元素加1可以等价为该元素减1,其它元素不动。那么方法如下:
1. 找到最小的元素
2. 计算每个元素和这个最小元素的差
3. 差加起来就是总步数
'''
r=0
m=min(arr)
foriinarr:
r+= (i-m)
returnr
# medium: https://www.lintcode.com/problem/1907