2024-06-11发表2025-01-15更新LeetCode每日一题几秒读完 (大约88个字)0次访问419. 甲板上的战舰甲板上的战舰 难度: medium 原始链接: https://leetcode.cn/problems/battleships-in-a-board 标签: 脑筋急转弯 解法一: 脑筋急转弯go123456789101112131415func countBattleships(board [][]byte) int { ans := 0 rLen := len(board) cLen := len(board[0]) for r := 0; r < rLen; r++ { for c := 0; c < cLen; c++ { if board[r][c] == 'X' && (r == 0 || r > 0 && board[r-1][c] == '.') && (c == 0 || c > 0 && board[r][c-1] == '.') { ans++ } } } return ans} 419. 甲板上的战舰https://wuhunyu.top/leetcode/2024/06/battleships-in-a-board/index.html作者wuhunyu发布于2024-06-11更新于2025-01-15许可协议#脑筋急转弯