Untitled
func countServers(grid [][]int) int { rows := make(map[int]int, 0) cols := make(map[int]int, 0) n := len(grid) m := len(grid[0]) for i:=0;i<n;i++ { for j:=0;j<m;j++ { if grid[i][j] == 0 { continue } rows[i]++ cols[j]++ } } ans := 0 for i:=0;i<n;i++ { for j:=0;j<m;j++ { if grid[i][j] == 0 { continue } if rows[i]>=2 || cols[j]>=2 { ans++ } } } return ans }
Leave a Comment