++가 들어있으면 a라는 변수를 만들어서 +=1 해주고 아니면 -=1 해주는 단순한 문제
스위프트:
class Solution {
func finalValueAfterOperations(_ operations: [String]) -> Int {
var a = 0
for i in operations{
if i.contains("++"){
a+=1
}
else{
a-=1
}
}
return a
}
}
파이썬:
class Solution:
def finalValueAfterOperations(self, operations: List[str]) -> int:
x=0
for i in range(len(operations)):
if "++" in operations[i]:
x+=1
else:
x-=1
return x
'리트코드 풀이' 카테고리의 다른 글
Leetcode 1108 풀이(파이썬, 스위프트) (0) | 2022.02.05 |
---|---|
Leetcode 2114 풀이(파이썬, 스위프트) (0) | 2022.02.04 |
Leetcode 1672 풀이(파이썬, 스위프트) (0) | 2022.02.04 |
Leetcode 1480 풀이(파이썬, 스위프트) (0) | 2022.02.03 |
리트코드 1119 풀이(파이썬, 스위프트) (0) | 2022.02.03 |