题解 | #棋子翻转#
棋子翻转
http://www.nowcoder.com/practice/a8c89dc768c84ec29cbf9ca065e3f6b4
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param A int整型二维数组
# @param f int整型二维数组
# @return int整型二维数组
#
class Solution:
def flipChess(self , A: List[List[int]], f: List[List[int]]) -> List[List[int]]:
# write code here
for i,j in f:
i =i-1
j=j-1
if i-1>=0 and j>=0 and A[i-1][j]==0:A[i-1][j]=1
elif i-1>=0 and j>=0 and A[i-1][j]==1:A[i-1][j]=0
if i>=0 and j-1>=0 and A[i][j-1]==0:A[i][j-1]=1
elif i>=0 and j-1>=0 and A[i][j-1]==1:A[i][j-1]=0
if i<=3 and j+1<=3 and A[i][j+1]==0:A[i][j+1]=1
elif i<=3 and j+1<=3 and A[i][j+1]==1:A[i][j+1]=0
if i+1<=3 and j<=3 and A[i+1][j]==0:A[i+1][j]=1
elif i+1<=3 and j<=3 and A[i+1][j]==1:A[i+1][j]=0
return A
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param A int整型二维数组
# @param f int整型二维数组
# @return int整型二维数组
#
class Solution:
def flipChess(self , A: List[List[int]], f: List[List[int]]) -> List[List[int]]:
# write code here
for i,j in f:
i =i-1
j=j-1
if i-1>=0 and j>=0 and A[i-1][j]==0:A[i-1][j]=1
elif i-1>=0 and j>=0 and A[i-1][j]==1:A[i-1][j]=0
if i>=0 and j-1>=0 and A[i][j-1]==0:A[i][j-1]=1
elif i>=0 and j-1>=0 and A[i][j-1]==1:A[i][j-1]=0
if i<=3 and j+1<=3 and A[i][j+1]==0:A[i][j+1]=1
elif i<=3 and j+1<=3 and A[i][j+1]==1:A[i][j+1]=0
if i+1<=3 and j<=3 and A[i+1][j]==0:A[i+1][j]=1
elif i+1<=3 and j<=3 and A[i+1][j]==1:A[i+1][j]=0
return A