add new solutions
This commit is contained in:
parent
1f0aa6d417
commit
efc7e67367
7 changed files with 215 additions and 2 deletions
27
solutions/29/q2946/solution.go
Normal file
27
solutions/29/q2946/solution.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// Package q2946 implements a solution for https://leetcode.com/problems/matrix-similarity-after-cyclic-shifts/
|
||||
package q2946
|
||||
|
||||
func areSimilar(mat [][]int, k int) bool {
|
||||
w := len(mat[0])
|
||||
k %= w
|
||||
if k == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
for r := range mat {
|
||||
for c := range w {
|
||||
var shifted int
|
||||
if r%2 == 0 {
|
||||
shifted = (c + k) % w
|
||||
} else {
|
||||
shifted = (c + w - k) % w
|
||||
}
|
||||
if mat[r][shifted] != mat[r][c] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
var _ = areSimilar
|
||||
Loading…
Add table
Add a link
Reference in a new issue