Re: [闲聊] 每日leetcode

楼主: DJYOMIYAHINA (通通打死)   2024-07-05 08:46:21
写出一坨大便
对不起对不起对不起
早上拉屎应该很正常吧:(
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]
作者: sustainer123 (caster)   2024-07-05 08:49:00
太早了吧
作者: rainkaras (rainkaras)   2024-07-05 09:04:00
宝 你还有在上班吗
作者: smart0eddie (smart0eddie)   2024-07-05 09:08:00
ㄉㄕ

Links booklink

Contact Us: admin [ a t ] ucptt.com