Leetcode Note: Go - Check if Every Row and Column Contains All Numbers

Check if Every Row and Column Contains All Numbers - LeetCode
https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers/

  • Go 言語で取り組んだメモ

回答

Funny solution with Go - Check if Every Row and Column Contains All Numbers - LeetCode
https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers/solutions/2464267/funny-solution-with-go/

func checkValid(matrix [][]int) bool {
    n := len(matrix)
    
    for i := 0; i < n; i++ {
        check := make([]int, n)
        
        for j := 0; j < n; j++ {
            check[matrix[i][j]-1] = n+1
        }
        
        for i := 0; i < n; i++ {
            if check[i] == 0 {
                return false
            }
        }
    }
    
    for i := 0; i < n; i++ {
        check := make([]int, n)
        
        for j := 0; j < n; j++ {
            check[matrix[j][i]-1] = n+1
        }
        
        for i := 0; i < n; i++ {
            if check[i] == 0 {
                return false
            }
        }
    }
    
    return true
}