class Solution:
def numRookCaptures(self, board: 'List[List[str]]') -> int:
basei = 0
basej = 0
row = len(board)
coloum = len(board[0]) for i in range(row):
for j in range(coloum):
if board[i][j] == 'R':
basei=i
basej=j
break
count = 0
for up in range(basei-1,-1,-1):
if board[up][basej]=='B':
break
if board[up][basej]=='p':
count+=1
break
for down in range(basei+1,row):
if board[down][basej]=='B':
break
if board[down][basej]=='p':
count+=1
break
for left in range(basej-1,-1,-1):
if board[basei][left]=='B':
break
if board[basei][left]=='p':
count+=1
break
for right in range(basej+1,coloum):
if board[basei][right]=='B':
break
if board[basei][right]=='p':
count+=1
break
return count

leetcode999的更多相关文章

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

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

随机推荐

  1. SpringBoot使用redis缓存List

    一.概述 最近在做性能优化,之前有一个业务是这样实现的: 1.温度报警后第三方通讯管理机直接把报警信息保存到数据库: 2.我们在数据库中添加触发器,(BEFORE INSERT)根据这条报警信息处理业 ...

  2. leedcode_贪心算法系列

    861. 翻转矩阵后的得分 思路: 行首的权值最大,故首先将其置1; 每列由于权值相同,故只需要将0多于1的情况反转即可 763. 划分字母区间 思路: 1.计算每个字母的最右边界下标,并记录到新数组 ...

  3. MariaDB基础命令

    关闭防火墙和selinux #systemctl stop firewalld 安装服务端和客户端mariadb # yum install mariadb-server mariadb -y mar ...

  4. python基础介绍

    一. 1.计算机基础 cpu:运算和控制:速度:飞机 内存:临时存储,供给cup数据,断电数据清空.成本高,速度:高铁 硬盘:相当于电脑的数据库,存储大量数据,数据永久保存(除非物理结构被破坏).速度 ...

  5. 多级字典表单的Python实现

    需求: 可依次选择进入各子菜单 可从任意一层往回退到上一层 可从任意一层退出程序 数据结构 menu = { '北京':{ '海淀':{ '五道口':{ 'soho':{}, '网易':{}, 'go ...

  6. TextView-- 测量文字宽度

    https://my.oschina.net/lengwei/blog/637380; http://blog.csdn.net/mare_blue/article/details/51388403; ...

  7. sqlserver 模糊查询,连表,聚合函数,分组

    use StudentManageDB go select StudentName,StudentAddress from Students where StudentAddress like '天津 ...

  8. 使用SecureCRT软件运维的配置习惯

    使用 SecureCRT 软件运维的配置习惯 作者:Eric 微信:loveoracle11g 选项--->全局选项 配置文件存放路径 默认CRT配置的配置文件在C盘 常规--->默认会话 ...

  9. 关于easyUI异步获取数据格式问题

    后台向easyUI一般写String类型的数据 成功之后的回调函数中:应将数据转为json格式    $.parsonJSON success:function(result){            ...

  10. jQuery+html+css-自己写的分页

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...