-
Notifications
You must be signed in to change notification settings - Fork 4
/
1169. Invalid Trasactions.go
52 lines (50 loc) · 1.06 KB
/
1169. Invalid Trasactions.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
45
46
47
48
49
50
51
52
package main
import (
"strconv"
"strings"
)
func invalidTransactions(transactions []string) []string {
res := make([]string, 0)
tb := make(map[string]map[int]string)
for i := range transactions {
ss := strings.Split(transactions[i], ",")
name := ss[0]
time, _ := strconv.Atoi(ss[1])
location := ss[3]
if _, ok := tb[name]; !ok {
tb[name] = make(map[int]string)
}
if _, ok := tb[name][time]; ok {
tb[name][time] = "xx"
} else {
tb[name][time] = location
}
}
for i := range transactions {
ss := strings.Split(transactions[i], ",")
name := ss[0]
time, _ := strconv.Atoi(ss[1])
amount, _ := strconv.Atoi(ss[2])
location := ss[3]
if amount > 1000 {
res = append(res, transactions[i])
continue
}
v := tb[name]
added := false
for j := time - 60; j < time+61; j++ {
if added {
break
}
if _, ok := v[j]; ok && j != time && v[j] != location {
added = true
res = append(res, transactions[i])
}
if v[j] == "xx" && j == time {
added = true
res = append(res, transactions[i])
}
}
}
return res
}