JZ66 机器人的运动范围 python.pdfVIP

  • 1
  • 0
  • 约2.05千字
  • 约 3页
  • 2026-06-10 发布于浙江
  • 举报

JZ66机机器器人人的的运运动动范范围围

myversion

dfs

错错误误记记录录

1.a=b=[xforxinrange(n)]会使a、b指向同一空间

2.由于机器人从[0,0]开始运动,因此只有向和向下两个方向可以走

classSolution:

defdfs(self,i,j,thre,rows,cols):

#print(i,j)

ifi0ori=rowsorj0orj=colsorself.visit[i][j]:

#超出边界/已访问过

return

row,col=i,j

i_su=j_su=0

whilerow:

i_su+=row%10

row=row//10

whilecol:

j_su+=col%10

col=col//10

ifi_su+j_suthre:

#不

文档评论(0)

1亿VIP精品文档

相关文档