leetcode-5.9[680. 验证回文字符串 II、941. 有效的山脉数组、1037. 有效的回旋镖](python实现)

题目1

在这里插入图片描述

题解1

class Solution:
    def validPalindrome(self, s: str) -> bool:
        l, r = 0, len(s) - 1
        while l < r:
            if s[l] != s[r]:
                case1, case2 = s[l:r], s[l+1:r+1]
                # 如果原数组去头,去尾的两个数组有一个为回文,则整体为回文
                return case1 == case1[::-1] or case2 == case2[::-1]
            l, r = l+1, r-1
        return True

附上题目链接

题目2

在这里插入图片描述

题解2

class Solution:
    def validMountainArray(self, A: List[int]) -> bool:
        if len(A) < 3:
            return False
        a = A.index(max(A))
        if a == 0 or a == len(A) - 1:
            return False
        for i in range(a):
            if A[i] >= A[i+1]:
                return False
        for i in range(a,len(A)-1):
            if A[i] <= A[i+1]:
                return False
        return True

附上题目链接

题目3

在这里插入图片描述

题解3

class Solution:
    def isBoomerang(self, points: List[List[int]]) -> bool:
        # 判断三个点相同
        if not(points[0] != points[1] != points[2]):
            return False
        # 比较斜率
        k1 = (points[1][1]-points[0][1])/(points[1][0]-points[0][0]) if points[1][0]-points[0][0] != 0 else 'non-exist'
        k2 = (points[2][1]-points[1][1])/(points[2][0]-points[1][0]) if points[2][0]-points[1][0] != 0 else 'non-exist'
        return k1 != k2
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值