Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func countBattleships(_ board: [[Character]]) -> Int {
- var res:Int = 0
- for i in 0..<board.count {
- for j in 0..<board[i].count {
- if i>0 && board[i-1][j] == "X"{
- continue
- } else if j>0 && board[i][j-1] == "X" {
- continue
- } else if i>0 && j>0 {
- if board[i-1][j] == "." && board[i][j-1] == "." && board[i][j] == "X"{
- res += 1
- }
- continue
- } else if board[i][j] == "X" {
- res += 1
- }
- }
- }
- return res
- }
Add Comment
Please, Sign In to add comment