add new solutions
This commit is contained in:
parent
9c2c959a9b
commit
9a10695e8c
29 changed files with 1074 additions and 2 deletions
26
solutions/2/q221/solution.go
Normal file
26
solutions/2/q221/solution.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package q221
|
||||
|
||||
func maximalSquare(matrix [][]byte) int {
|
||||
w, h := len(matrix[0]), len(matrix)
|
||||
|
||||
maxSq := make([]int16, w+h)
|
||||
maxV := make([]int16, w)
|
||||
ret := 0
|
||||
for y := range h {
|
||||
var maxH int16
|
||||
for x := range w {
|
||||
if matrix[y][x] == '0' {
|
||||
maxH, maxV[x], maxSq[x-y+h] = 0, 0, 0
|
||||
continue
|
||||
}
|
||||
|
||||
maxH++
|
||||
maxV[x]++
|
||||
maxSq[x-y+h] = min(maxH, maxV[x], maxSq[x-y+h]+1)
|
||||
ret = max(ret, int(maxSq[x-y+h]))
|
||||
}
|
||||
}
|
||||
return ret * ret
|
||||
}
|
||||
|
||||
var _ = maximalSquare
|
||||
Loading…
Add table
Add a link
Reference in a new issue