Skip to content

Commit 0cd7497

Browse files
committed
Time: 4 ms (4.54%), Space: 17.7 MB (60.7%) - LeetHub
1 parent d6611ca commit 0cd7497

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# time complexity: O(n)
2+
# space complexity: O(1)
3+
from typing import List
4+
5+
6+
class Solution:
7+
def finalValueAfterOperations(self, operations: List[str]) -> int:
8+
count = 0
9+
for operation in operations:
10+
if operation[0] == '+' or operation[-1] == '+':
11+
count += 1
12+
else:
13+
count -= 1
14+
return count
15+
16+
17+
operations = ["--X", "X++", "X++"]
18+
print(Solution().finalValueAfterOperations(operations))
19+
operations = ["++X", "++X", "X++"]
20+
print(Solution().finalValueAfterOperations(operations))
21+
operations = ["X++", "++X", "--X", "X--"]
22+
print(Solution().finalValueAfterOperations(operations))

0 commit comments

Comments
 (0)