add new solutions

This commit is contained in:
kanna5 2025-12-23 17:05:50 +09:00
parent 62ed89abcc
commit ed8cd12d25
2 changed files with 89 additions and 0 deletions

View file

@ -0,0 +1,26 @@
package q209
import "math"
func minSubArrayLen(target int, nums []int) int {
minLen := math.MaxInt
l, sum := 0, 0
for r := range nums {
sum += nums[r]
for l < r && sum-nums[l] >= target {
sum -= nums[l]
l++
}
if sum >= target {
minLen = min(minLen, r-l+1)
}
}
if minLen == math.MaxInt {
return 0
}
return minLen
}
var _ = minSubArrayLen

63
solutions/q36/solution.go Normal file
View file

@ -0,0 +1,63 @@
package q36
func validateCol(board [][]byte, col int) bool {
var present [10]bool
for i := range 9 {
c := board[i][col]
if c != '.' {
if present[c-'0'] {
return false
}
present[c-'0'] = true
}
}
return true
}
func validateRow(board [][]byte, row int) bool {
var present [10]bool
for i := range 9 {
c := board[row][i]
if c != '.' {
if present[c-'0'] {
return false
}
present[c-'0'] = true
}
}
return true
}
func validateBox(board [][]byte, box int) bool {
xOffset := (box % 3) * 3
yOffset := (box / 3) * 3
var present [10]bool
for i := range 9 {
x := xOffset + i%3
y := yOffset + i/3
c := board[y][x]
if c != '.' {
if present[c-'0'] {
return false
}
present[c-'0'] = true
}
}
return true
}
func validate(board [][]byte) bool {
for i := range 9 {
if !validateCol(board, i) || !validateRow(board, i) || !validateBox(board, i) {
return false
}
}
return true
}
func isValidSudoku(board [][]byte) bool {
return validate(board)
}
var _ = isValidSudoku