Golang | Leetcode Golang题解之第419题棋盘上的战舰
题目:
题解:
func countBattleships(board [][]byte) (ans int) {for i, row := range board {for j, ch := range row {if ch == 'X' && !(i > 0 && board[i-1][j] == 'X' || j > 0 && board[i][j-1] == 'X') {ans++}}}return
}
题目:
题解:
func countBattleships(board [][]byte) (ans int) {for i, row := range board {for j, ch := range row {if ch == 'X' && !(i > 0 && board[i-1][j] == 'X' || j > 0 && board[i][j-1] == 'X') {ans++}}}return
}