2766. 重新放置石块

重新放置石块

解法一: 哈希

go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
func relocateMarbles(nums []int, moveFrom []int, moveTo []int) []int {
positions := make(map[int]bool)
for _, num := range nums {
positions[num] = true
}
n := len(moveFrom)
for i := 0; i < n; i++ {
positions[moveFrom[i]] = false
positions[moveTo[i]] = true
}
ans := []int{}
for position, exists := range positions {
if exists {
ans = append(ans, position)
}
}
sort.Ints(ans)
return ans
}
作者

wuhunyu

发布于

2024-07-24

更新于

2025-01-15

许可协议