Skip to content

Commit

Permalink
add: leetcode 419 solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Don2025 committed Jul 2, 2022
1 parent 3f0ef3a commit c217fa2
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package leetcode

func countBattleships(board [][]byte) (ans int) {
if len(board) == 0 || len(board[0]) == 0 {
return 0
}
for i := range board {
for j := range board[i] {
if board[i][j] == 'X' {
if i > 0 && board[i-1][j] == 'X' {
continue
}
if j > 0 && board[i][j-1] == 'X' {
continue
}
ans++
}
}
}
return
}

0 comments on commit c217fa2

Please sign in to comment.