forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1298.go
More file actions
24 lines (24 loc) · 679 Bytes
/
Copy path1298.go
File metadata and controls
24 lines (24 loc) · 679 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
func maxCandies(status []int, candies []int, keys [][]int, containedBoxes [][]int, initialBoxes []int) int {
q, res := initialBoxes, 0
for len(q) > 0 {
changed := false
for q_len := len(q); q_len > 0; q_len-- {
b := q[0]
q = q[1:]
if status[b] == 1 {
changed = true
res += candies[b]
q = append(q, containedBoxes[b]...)
for _, i := range keys[b] {
status[i] = 1
}
} else {
q = append(q, b)
}
}
if !changed {
return res
}
}
return res
}