https://leetcode.com/problems/final-value-of-variable-after-performing-operations/
package main
import (
"strings"
)
func main() {
operations := []string{"--X", "X++", "X++"}
finalValueAfterOperations(operations)
}
// 제출 코드
func finalValueAfterOperations(operations []string) int {
sum := 0
if len(operations) == 0 {
return sum
}
for _, v := range operations {
if strings.Contains(v, "+") {
sum += 1
} else {
sum -= 1
}
}
return sum
}
'Algorithm > Go' 카테고리의 다른 글
[Leetcode] Majority Element (0) | 2021.12.19 |
---|---|
[Leetcode] Maximum Number of Words You Can Type (0) | 2021.12.12 |
[LeetCode] Consecutive Characters (Go) (0) | 2021.12.06 |
[Leetcode] Two Sum (Go) (0) | 2021.12.06 |
[프로그래머스] 로또의 최고 순위와 최저 순위 (Go) (0) | 2021.11.28 |