Guest User

Untitled

a guest
Nov 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. func countBattleships(_ board: [[Character]]) -> Int {
  2. var res:Int = 0
  3. for i in 0..<board.count {
  4. for j in 0..<board[i].count {
  5. if i>0 && board[i-1][j] == "X"{
  6. continue
  7. } else if j>0 && board[i][j-1] == "X" {
  8. continue
  9. } else if i>0 && j>0 {
  10. if board[i-1][j] == "." && board[i][j-1] == "." && board[i][j] == "X"{
  11. res += 1
  12. }
  13. continue
  14. } else if board[i][j] == "X" {
  15. res += 1
  16. }
  17. }
  18. }
  19. return res
  20. }
Add Comment
Please, Sign In to add comment