Skip to content

Commit 9c3475b

Browse files
committed
Time: 86 ms (20.54%), Space: 26.7 MB (36.79%) - LeetHub
1 parent 22faaff commit 9c3475b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# time complexity: O(n)
2+
# space complexity: O(1)
3+
from typing import List
4+
5+
6+
class Solution:
7+
def minNumberOperations(self, target: List[int]) -> int:
8+
result = target[0]
9+
for i in range(1, len(target)):
10+
result += max(target[i] - target[i - 1], 0)
11+
return result
12+
13+
14+
target = [1, 2, 3, 2, 1]
15+
print(Solution().minNumberOperations(target))
16+
target = [3, 1, 1, 2]
17+
print(Solution().minNumberOperations(target))
18+
target = [3, 1, 5, 4, 2]
19+
print(Solution().minNumberOperations(target))

0 commit comments

Comments
 (0)