Re: [閒聊] 每日leetcode已回收
寫出一坨大便
對不起對不起對不起
早上拉屎應該很正常吧:(
def nodesBetweenCriticalPoints(self, head: Optional[ListNode]) -> List[int]:
first_idx, last_idx,idx = 10**6,-1,0
mindis = 10**6
pre_idx = -1
pre_val = -1
while head is not None:
if pre_val != -1 and head.next is not None:
if (pre_val<head.val and head.next.val<head.val) or
(pre_val>head.val and head.next.val>head.val):
first_idx = min(first_idx, idx)
last_idx = max(last_idx, idx)
mindis = 10**6 if pre_idx == -1 else min(idx-pre_idx, mindis)
pre_idx = idx
pre_val = head.val
head = head.next
idx += 1
return [-1 if mindis == 10**6 else mindis, -1 if first_idx==10**6 and
last_idx==-1 or first_idx==last_idx else last_idx-first_idx]
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.229.37.69 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1720140383.A.D16.html
推
07/05 08:49,
1年前
, 1F
07/05 08:49, 1F
→
07/05 09:04,
1年前
, 2F
07/05 09:04, 2F
推
07/05 09:08,
1年前
, 3F
07/05 09:08, 3F
討論串 (同標題文章)
完整討論串 (本文為第 446 之 1554 篇):