[Leetcode] 每日两题 2058 2108 -day84

2058. 找出临界点之间的最小和最大距离

在这里插入图片描述

遍历整个链表 然后判断 每个节点是否为临界点 ,之后将位置放入列表中,同时记录最近距离,最后返回列表首尾差值即为最大距离


class Solution:
    def nodesBetweenCriticalPoints(self, head: Optional[ListNode]) -> List[int]:
        res1,res2 =-1,-1
        dislist = []
        node = head
        nodenex =head.next
        num = 1
        while nodenex:
            if nodenex.next and ((node.val<nodenex.val and nodenex.val>nodenex.next.val) or (node.val>nodenex.val and nodenex.val<nodenex.next.val)) :
                if dislist:
                    if res1 ==-1:
                        res1 =num-dislist[-1]
                    else :
                        res1 =min(res1,num-dislist[-1])
                dislist.append(num)

            num += 1
            node =nodenex
            nodenex =nodenex.next
        if len(dislist)>=2:
            res2 = dislist[-1]-dislist[0]

        return [res1,res2]
2108. 找出数组中的第一个回文字符串

在这里插入图片描述

字符串题 直接判断是否单词是回文

class Solution:
    def firstPalindrome(self, words: List[str]) -> str:

        for  word in words:
            if word == word[::-1]:
                return word
        return ""
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值