999. 车的可用捕获量

在一个 8 x 8 的棋盘上,有一个白色车(rook)。也可能有空方块,白色的象(bishop)和黑色的卒(pawn)。它们分别以字符 “R”,“.”,“B” 和 “p” 给出。大写字符表示白棋,小写字符表示黑棋。

车按国际象棋中的规则移动:它选择四个基本方向中的一个(北,东,西和南),然后朝那个方向移动,直到它选择停止、到达棋盘的边缘或移动到同一方格来捕获该方格上颜色相反的卒。另外,车不能与其他友方(白色)象进入同一个方格。

返回车能够在一次移动中捕获到的卒的数量。

示例 1:

输入:[[".",".",".",".",".",".",".","."],[".",".",".",“p”,".",".",".","."],[".",".",".",“R”,".",".",".",“p”],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".",“p”,".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]

输出:3

解释:

在本例中,车能够捕获所有的卒。

示例 2:

输入:[[".",".",".",".",".",".",".","."],[".",“p”,“p”,“p”,“p”,“p”,".","."],[".",“p”,“p”,“B”,“p”,“p”,".","."],[".",“p”,“B”,“R”,“B”,“p”,".","."],[".",“p”,“p”,“B”,“p”,“p”,".","."],[".",“p”,“p”,“p”,“p”,“p”,".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]

输出:0

解释:

象阻止了车捕获任何卒。

示例 3:

输入:[[".",".",".",".",".",".",".","."],[".",".",".",“p”,".",".",".","."],[".",".",".",“p”,".",".",".","."],[“p”,“p”,".",“R”,".",“p”,“B”,"."],[".",".",".",".",".",".",".","."],[".",".",".",“B”,".",".",".","."],[".",".",".",“p”,".",".",".","."],[".",".",".",".",".",".",".","."]]

输出:3

解释:

车可以捕获位置 b5,d6 和 f5 的卒。

提示:

board.length == board[i].length == 8

board[i][j] 可以是 ‘R’,’.’,‘B’ 或 ‘p’

只有一个格子上存在 board[i][j] == ‘R’

Java实现 LeetCode 999 车的可用捕获量(简单搜索)的更多相关文章

  1. Leetcode 999. 车的可用捕获量

    999. 车的可用捕获量  显示英文描述 我的提交返回竞赛   用户通过次数255 用户尝试次数260 通过次数255 提交次数357 题目难度Easy 在一个 8 x 8 的棋盘上,有一个白色车(r ...

  2. 【LeetCode】Available Captures for Rook(车的可用捕获量)

    这道题是LeetCode里的第999道题. 题目叙述: 在一个 8 x 8 的棋盘上,有一个白色车(rook).也可能有空方块,白色的象(bishop)和黑色的卒(pawn).它们分别以字符 &quo ...

  3. [Swift]LeetCode999. 车的可用捕获量 | Available Captures for Rook

    在一个 8 x 8 的棋盘上,有一个白色车(rook).也可能有空方块,白色的象(bishop)和黑色的卒(pawn).它们分别以字符 “R”,“.”,“B” 和 “p” 给出.大写字符表示白棋,小写 ...

  4. Java for LeetCode 216 Combination Sum III

    Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...

  5. Java for LeetCode 214 Shortest Palindrome

    Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...

  6. Java for LeetCode 212 Word Search II

    Given a 2D board and a list of words from the dictionary, find all words in the board. Each word mus ...

  7. Java for LeetCode 211 Add and Search Word - Data structure design

    Design a data structure that supports the following two operations: void addWord(word)bool search(wo ...

  8. Java for LeetCode 210 Course Schedule II

    There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...

  9. Java for LeetCode 200 Number of Islands

    Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...

随机推荐

  1. OpenCV 经纬法将鱼眼图像展开

    文章目录 前言 理论部分 鱼眼展开流程 鱼眼标准坐标计算 标准坐标系与球坐标的转换 代码实现 测试效果如下图 总结 this demo on github 前言 鱼眼镜头相比传统的镜头,视角更广,采集 ...

  2. Linux共享库简单总结

    库 静态库 编译的二进制会重新包含一份静态库的副本 共享库 编译 gcc -shared -o file.c -fPIC 链接 ld ld-linux.so.2 可执行程序–>动态依赖表 流程: ...

  3. 设计模式之GOF23策略

    策略模式strategy 场景:对不同客户的不同报价策略 如果采用if else不易扩展,不符合开闭原则,可以采用策略模式 策略模式: 对应于解决某一个问题的算法族,允许其中一个算法去解决某一问题,同 ...

  4. Python脚本:linux上将筛选的文件夹复制到另一个目录,保存目录结构以及文件和文件夹操作方法

    import os,shutil def newDir(dir_path): if not os.path.exists(dir_path): os.makedirs(dir_path) def co ...

  5. Unity接入友盟分享遇到的坑

    最近项目接了一下友盟分享的SDK,中间遇到了几个坑,写下几条注意事项记录一下. 接入之前需要准备友盟开发者账号,相应平台开发者账号(微信.QQ.新浪微博)等... 安卓端: 1.确保 AndroidM ...

  6. 00002-layui 右侧呼出页面,PopupLayer

    我这里的功能是弹出 右侧搜索 的页面: top.layui.admin.popupRight({ id: 'LAY_business_PopupLayer' ,area: '350px' ,succe ...

  7. Codeforces1157A(A题)Reachable Numbers

    A. Reachable Numbers Let's denote a function f(x)f(x) in such a way: we add 11 to xx, then, while th ...

  8. Angular的面试题

    1.Aangular中组件之间通信的方式 答案:Props down 1.调用子组件,通过自定义属性传值 2.子组件内部通过Input来接收属性的值 Events  up 1.在父组件中定义一个有参数 ...

  9. flask之session

    ''' session使用: session创建: (1)导入session from flask import session (2)设置secret_key密钥 app.secret_key='s ...

  10. 10 分离式web框架

    10 分离式web框架 wsgiref模块: 将http请求封装成以键值对的形式封装成字典environ: "PATH_INFO"对应的值为请求文件路径, “QUERY_STRIN ...