battleships-in-a-board
2016-10-16 14:15
330 查看
https://leetcode.com/problems/battleships-in-a-board/ // 采用的是排除法,看船的最后一个节点 public class Solution { public int countBattleships(char[][] board) { int rows = board.length; int cols = rows > 0 ? board[0].length : 0; if (rows == 0 || cols == 0) { return 0; } int ret = 0; for (int i=0; i<rows; i++) { for (int j=0; j<cols; j++) { if (board[i][j] == 'X') { if ((i+1>=rows || board[i+1][j]=='.') && (j+1>=cols || board[i][j+1]=='.')) { ret++; } } } } return ret; } }
相关文章推荐
- leetcode 419 Battleships in a Board C++
- Battleships in a Board 题解
- Leetcode 419 Battleships in a Board
- Battleships in a Board战列舰队问题解法分析
- LeetCode:419. Battleships in a Board
- Battleships in a Board(统计战舰数)
- LeetCode #419: Battleships in a Board
- [LeetCode]Battleships in a Board 战舰数目
- Battleships in a Board
- LeetCode[419] Battleships in a Board
- [LeetCode] Battleships in a Board 平板上的战船
- Battleships in a Board [Leetcode]
- LeetCode Battleships in a Board
- LeetCode 419 Battleships in a Board (DFS 或 模拟)
- Battleships in a Board
- leetcode oj java Battleships in a Board
- Battleships in a Board
- Battleships in a Board
- Battleships in a Board问题及解法
- LightOJ1010---Knights in Chessboard (规律题)