-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path679.go
More file actions
55 lines (47 loc) · 1.21 KB
/
679.go
File metadata and controls
55 lines (47 loc) · 1.21 KB
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
package main
import "math"
const (
EPSILON = 1E-6
)
func judgePoint24(nums []int) bool {
transNums := []float64{}
for i := 0; i < len(nums); i ++ {
transNums = append(transNums, float64(nums[i]))
}
return judge(transNums)
}
func judge(nums []float64) bool {
l := len(nums)
if l == 0 {
return false
}
if (l == 1) {
return math.Abs(nums[0] - 24) < EPSILON
}
for i := 0; i < l; i ++ {
for j := 0; j < l; j ++ {
if i == j {
continue
}
newNums := []float64{}
for k := 0; k < l; k ++ {
if k != i && k != j {
newNums = append(newNums, nums[k])
}
}
if i < j && judge(append(newNums, nums[i] + nums[j])) {
return true
}
if judge(append(newNums, nums[i] - nums[j])) {
return true
}
if i < j && judge(append(newNums, nums[i] * nums[j])) {
return true
}
if math.Abs(nums[j]) > EPSILON && judge(append(newNums, nums[i] / nums[j])) {
return true
}
}
}
return false
}