-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution2011.go
44 lines (38 loc) · 1 KB
/
solution2011.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package solution2011
// ============================================================================
// 2011. Final Value of Variable After Performing Operations
// URL: https://leetcode.com/problems/final-value-of-variable-after-performing-operations/
// ============================================================================
/*
$ go test -bench=. -benchmem
goos: linux
goarch: amd64
pkg: GoLeetCode/solutions/2011---Final-Value-of-Variable-After-Performing-Operations
cpu: 13th Gen Intel(R) Core(TM) i7-13700K
Benchmark_finalValue-24 1000000000 1.138 ns/op 0 B/op 0 allocs/op
PASS
*/
func finalValueAfterOperations(operations []string) int {
ans := 0
for _, operation := range operations {
switch operation[1] {
case '+':
ans++
case '-':
ans--
}
}
return ans
}
func finalValueAfterOperations_if(operations []string) int {
ans := 0
for i := 0; i < len(operations); i++ {
switch operations[i][1] {
case '+':
ans++
case '-':
ans--
}
}
return ans
}