Simple but long python solution


#1

class Solution:
# @param A : list of strings
# @return a list of list of integers
def queenAttack(self, a):
A=[]
for items in a:
A.append(list(map(int,list(items))))
# print(A)
r=len(A)
c=len(A[0])
rr=[[0 for i in range©] for i in range®]
mk={}
for i in range®:
for j in range©:
if A[i][j]==1:
rr[i][j]=-1
mk[i,j]=0
for items in mk.keys():
i=items[0]
j=items[1]
for jj in range(i+1,r):
if rr[jj][j]==-1:
mk[jj,j]+=1
break
else:
rr[jj][j]+=1
for jj in range(i-1,-1,-1):
if rr[jj][j]==-1:
mk[jj,j]+=1
break
else:
rr[jj][j]+=1
for jj in range(j+1,c):
if rr[i][jj]==-1:
mk[i,jj]+=1
break
else:
rr[i][jj]+=1
for jj in range(j-1,-1,-1):
if rr[i][jj]==-1:
mk[i,jj]+=1
break
else:
rr[i][jj]+=1
m=i+1
n=j+1
while m<r and n<c:
if rr[m][n]==-1:
mk[m,n]+=1
break
rr[m][n]+=1
m+=1
n+=1
m=i-1
n=j-1
while m>=0 and n>=0:
if rr[m][n]==-1:
mk[m,n]+=1
break
rr[m][n]+=1
m-=1
n-=1
m=i-1
n=j+1
while m>=0 and n<c:
if rr[m][n]==-1:
mk[m,n]+=1
break
rr[m][n]+=1
m-=1
n+=1
m=i+1
n=j-1
while m=0:
if rr[m][n]==-1:
mk[m,n]+=1
break
rr[m][n]+=1
m+=1
n-=1
for items in mk.keys():
rr[items[0]][items[1]]=mk[items]
return rr