题目要求

In an alien language, surprisingly they also use english lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters.

Given a sequence of words written in the alien language, and the order of the alphabet, return true if and only if the given words are sorted lexicographicaly in this alien language.

题目分析及思路

给定一组字符串以及一个字母表顺序,判断这组字符串是否是按照给定字母表顺序排列的。可以对该组字符串进行两两比较,依据最短字符串长度分别遍历两个字符串。若前者的字符顺序小于后者的,则跳出循环,继续比较其他字符串;若前者的字符顺序大于后者的,则返回False;若相等则继续比较,直到所有字符都相等,若较长字符串在前则返回False。

python代码

class Solution:

def isAlienSorted(self, words: List[str], order: str) -> bool:

for idx in range(1, len(words)):

len_min = min(len(words[idx-1]), len(words[idx]))

flag = 0

while len_min:

if order.index(words[idx-1][flag]) < order.index(words[idx][flag]):

break

elif order.index(words[idx-1][flag]) > order.index(words[idx][flag]):

return False

len_min -= 1

flag += 1

if len_min == 0 and len(words[idx-1]) > len(words[idx]):

return False

return True

LeetCode 953 Verifying an Alien Dictionary 解题报告的更多相关文章

  1. 【LeetCode】953. Verifying an Alien Dictionary 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  2. LeetCode 953. Verifying an Alien Dictionary

    原题链接在这里:https://leetcode.com/problems/verifying-an-alien-dictionary/ 题目: In an alien language, surpr ...

  3. LeetCode 953. Verifying an Alien Dictionary (验证外星语词典)

    题目标签:HashMap 题目给了我们一个 order 和 words array,让我们依照order 来判断 words array 是否排序. 利用hashmap 把order 存入 map, ...

  4. 【Leetcode_easy】953. Verifying an Alien Dictionary

    problem 953. Verifying an Alien Dictionary solution: class Solution { public: bool isAlienSorted(vec ...

  5. 【leetcode】953. Verifying an Alien Dictionary

    题目如下: In an alien language, surprisingly they also use english lowercase letters, but possibly in a ...

  6. 【LeetCode】676. Implement Magic Dictionary 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 汉明间距 日期 题目地址:https://le ...

  7. 953.Verifying an Alien Dictionary(Map)

    In an alien language, surprisingly they also use english lowercase letters, but possibly in a differ ...

  8. Verifying an Alien Dictionary

    2019-11-24 22:11:30 953. Verifying an Alien Dictionary 问题描述: 问题求解: 这种问题有一种解法是建立新的排序和abc排序的映射,将这里的str ...

  9. 【LeetCode】760. Find Anagram Mappings 解题报告

    [LeetCode]760. Find Anagram Mappings 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/find ...

随机推荐

  1. 【6集iCore3_ADP触摸屏驱动讲解视频】6-5 底层驱动之SDRAM读写(下)

    源视频包下载地址: 链接:http://pan.baidu.com/s/1jIC2LKy 密码:zyn3   银杏科技优酷视频发布区: http://i.youku.com/gingko8  

  2. 深刻理解Python中的元类(metaclass)【转】

    译注:这是一篇在Stack overflow上很热的帖子.提问者自称已经掌握了有关Python OOP编程中的各种概念,但始终觉得元类(metaclass)难以理解.他知道这肯定和自省有关,但仍然觉得 ...

  3. Java知多少(12)运算符

    Java中的运算符和C/C++相差无几. 数学运算符 数学运算,结果为一个数值.见下表: 运算符 说明 举例 + 加法 1 + 2 - 减法 4 - 3.4 * 乘法 7 * 1.5 / 除法 3.5 ...

  4. Go指南练习_错误

    源地址 https://tour.go-zh.org/methods/20 一.题目描述 从之前的练习中复制 Sqrt 函数,修改它使其返回 error 值. Sqrt 接受到一个负数时,应当返回一个 ...

  5. Cisco VTP中继协议配置

    VTP协议: VLAN中继协议,VTP,VLAN TRUNKING PROTOCOL,是CISCO专用协议,大多数交换机都支持该协议.VTP负责在VTP域内同步VLAN信息, 这样就不必在每个交换上配 ...

  6. 如何使用ABBYY FineReader 12将JPEG文件转换成Word文档

    日常工作中处理JPEG格式的图像文件时,有时需要转换成Word文档进行编辑,市场上应用而生了很多转换工具,相信不少人听说过OCR(光学字符识别)软件,可以用来转换图像文件,而在OCR软件中, ABBY ...

  7. 【JAVA-JDT-AST】Java抽象语法树的构建、遍历及转成dot格式(附Github源码)

    Background: 最近为了重现tree-based clone detection的论文:L. Jiang, G. Misherghi, Z. Su, and S. Glondu. Deckar ...

  8. 四、K3 Cloud 开发插件《K3 Cloud事件、方法、函数》

    1.简单帐表/动态表单几个主要事件 //初始化 public override void Initialize() //构建动态列 public override BOS.Core.Report.Re ...

  9. [原]CentOS 7 网卡子接口的创建

    OS:CentOS 7 在linux上创建vlan需要加载802.1q模块: 1.检测OS是否已经加载802.1q模块 [root@controller ~]# modinfo 8021q filen ...

  10. Solr7.4.0的API(Solrj)操作及项目中的使用

    一.SolrJ的概念 solr单机版服务搭建:https://www.cnblogs.com/frankdeng/p/9615253.html solr集群版服务搭建:https://www.cnbl ...