C语言 | Leetcode C语言题解之第419题棋盘上的战舰

题目:

题解:

cpp 复制代码
int countBattleships(char** board, int boardSize, int* boardColSize){
    int row = boardSize;
    int col = boardColSize[0];
    int ans = 0;
    for (int i = 0; i < row; ++i) {
        for (int j = 0; j < col; ++j) {
            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 ans;
}
相关推荐
oplp8 小时前
第四章 C语言中的基本输入输出(六)
c语言
程序员东岸10 小时前
《数据结构——排序(中)》选择与交换的艺术:从直接选择到堆排序的性能跃迁
数据结构·笔记·算法·leetcode·排序算法
做怪小疯子12 小时前
LeetCode 热题 100——二叉树——二叉树的层序遍历&将有序数组转换为二叉搜索树
算法·leetcode·职场和发展
chengpei14712 小时前
I²C协议简介
c语言·开发语言
CoderYanger12 小时前
递归、搜索与回溯-记忆化搜索:38.最长递增子序列
java·算法·leetcode·1024程序员节
CoderYanger13 小时前
C.滑动窗口-越短越合法/求最长/最大——2958. 最多 K 个重复元素的最长子数组
java·数据结构·算法·leetcode·哈希算法·1024程序员节
say_fall14 小时前
C语言编程实战:每日一题:随机链表的复制
c语言·开发语言·链表
却话巴山夜雨时i14 小时前
394. 字符串解码【中等】
java·数据结构·算法·leetcode
leoufung14 小时前
LeetCode 230:二叉搜索树中第 K 小的元素 —— 从 Inorder 遍历到 Order Statistic Tree
算法·leetcode·职场和发展