作者DJYOMIYAHINA (通通打死)
看板Marginalman
標題Re: [閒聊] 每日leetcode
時間Fri Jul 5 08:46:21 2024
寫出一坨大便
對不起對不起對不起
早上拉屎應該很正常吧:(
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
推 sustainer123: 太早了吧 07/05 08:49
→ rainkaras: 寶 你還有在上班嗎 07/05 09:04
推 smart0eddie: ㄉㄕ 07/05 09:08