-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path74.go
More file actions
44 lines (39 loc) · 960 Bytes
/
74.go
File metadata and controls
44 lines (39 loc) · 960 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import "fmt"
func searchMatrix(matrix [][]int, target int) bool {
if len(matrix) == 0 || len(matrix[0]) == 0 {
return false
}
ret := false
for i := len(matrix) - 1; i >= 0; i -- {
if matrix[i][0] > target {
continue;
}
if (matrix[i][0]) == target {
return true
}
fmt.Println(i)
return binarySearch(matrix[i], target)
}
return ret
}
func binarySearch(matrix []int, target int) bool {
ret := false
for {
fmt.Println(matrix)
if len(matrix) == 0 {
return false
}
mid := len(matrix) / 2
if matrix[mid] == target {
return true
} else if matrix[mid] > target {
matrix = matrix[0: mid]
return binarySearch(matrix, target)
} else {
matrix = matrix[mid + 1:]
return binarySearch(matrix, target)
}
}
return ret
}