LeetCode题解(1433):检查字符串是否存在所有字母均大于或均小于另一串的序列的序列(Python)
发布日期:2021-06-29 19:58:40 浏览次数:3 分类:技术文章

本文共 731 字,大约阅读时间需要 2 分钟。

题目:(中等)

标签:字符串

解法 时间复杂度 空间复杂度 执行用时
Ans 1 (Python) O ( N l o g N + M l o g M ) O(NlogN+MlogM) O(NlogN+MlogM) O ( N + M ) O(N+M) O(N+M) 168ms (87.55%)
Ans 2 (Python)
Ans 3 (Python)

解法一(排序法):

class Solution:    def checkIfCanBreak(self, s1: str, s2: str) -> bool:        s1 = sorted(s1)        s2 = sorted(s2)        n = len(s1)        direction = None        for i in range(n):            if s1[i] < s2[i]:                if direction is None:                    direction = False                elif direction:                    return False            elif s1[i] > s2[i]:                if direction is None:                    direction = True                elif not direction:                    return False        return True

转载地址:https://dataartist.blog.csdn.net/article/details/108276009 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:LeetCode题解(1449):数位成本和为目标值的最大数字(Python)
下一篇:LeetCode题解(1432):改变一个整数能得到的最大差值(Python)

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2024年04月03日 15时52分30秒