Re: [閒聊] 每日leetcode
剩我寫的一坨了==
寫得非常坎坷
唉
一二三四五
def spiralMatrixIII(self, rows: int, cols: int, rStart: int, cStart: int) ->
List[List[int]]:
diff = [0,1,0,-1,0]
ans = [[rStart,cStart]]
idx = 0
while len(ans) < (rows*cols):
cur_i = idx
for i in range((cur_i//2+1)):
rStart += diff[cur_i%4]
cStart += diff[cur_i%4+1]
if 0<=rStart<rows and 0<=cStart<cols:
ans.append([rStart,cStart])
idx += 1
return ans
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.229.37.69 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1723133291.A.18D.html
→
08/09 00:08,
1年前
, 1F
08/09 00:08, 1F
推
08/09 00:14,
1年前
, 2F
08/09 00:14, 2F
→
08/09 00:46,
1年前
, 3F
08/09 00:46, 3F
→
08/09 00:48,
1年前
, 4F
08/09 00:48, 4F
討論串 (同標題文章)
完整討論串 (本文為第 672 之 1549 篇):