Skip to content

Commit 4dd53c1

Browse files
authored
Create array-ame.py
1 parent d2299dc commit 4dd53c1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

array-ame.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from typing import (
2+
List,
3+
)
4+
5+
class Solution:
6+
"""
7+
@param arr: the array
8+
@return: determine the number of moves to make all elements equals
9+
"""
10+
def array_game(self, arr: List[int]) -> int:
11+
# write your code here
12+
'''
13+
其它元素加1可以等价为该元素减1,其它元素不动。那么方法如下:
14+
1. 找到最小的元素
15+
2. 计算每个元素和这个最小元素的差
16+
3. 差加起来就是总步数
17+
'''
18+
r = 0
19+
m = min(arr)
20+
for i in arr:
21+
r += (i - m)
22+
return r
23+
# medium: https://www.lintcode.com/problem/1907

0 commit comments

Comments
 (0)