-
Notifications
You must be signed in to change notification settings - Fork 481
/
0936.go
55 lines (52 loc) · 1.31 KB
/
0936.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
53
54
55
func movesToStamp(stamp string, target string) []int {
s_len, t_len, t := len(stamp), len(target), []byte(target)
var check func(k int) bool
var compareArray func(a, b []byte) bool
check = func(k int) bool {
ret := false
for i := 0; i < s_len; i++ {
if t[k + i] != '?' {
if t[k + i] != stamp[i] {
return false
}
ret = true
}
}
return ret
}
compareArray = func(a, b []byte) bool {
for i := 0; i < t_len; i++ {
if a[i] != b[i] {
return false
}
}
return true
}
done := make([]byte, t_len)
for i := 0; i < t_len; i++ {
done[i] = '?'
}
res := make([]int, 0)
for !compareArray(done, t) {
move := false
for i := 0; i < t_len - s_len + 1; i++ {
if check(i) {
move = true;
res = append(res, i)
for j := i; j < i + s_len; j++ {
t[j] = '?'
}
}
}
if !move {
return []int{}
}
}
return reverse(res)
}
func reverse(s []int) []int {
for i, j := 0, len(s) - 1; i < j; i, j = i + 1, j - 1 {
s[i], s[j] = s[j], s[i]
}
return s
}