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.

Example 1:

Input: words = ["hello","leetcode"], order = "hlabcdefgijkmnopqrstuvwxyz"

Output: true

Explanation: As 'h' comes before 'l' in this language, then the sequence is sorted.

使用Map将字典序映射为数字,进行比较

class Solution {
public boolean compare(Map<Character,Integer> ch,String string1,String string2){
int len1 = string1.length();
int len2 = string2.length();
int len = len1 < len2 ?len1:len2;
for(int i =0;i<len;i++){
if(ch.get(string1.charAt(i)) < ch.get(string2.charAt(i))) return true;
else if(ch.get(string1.charAt(i)) == ch.get(string2.charAt(i)))
continue;
else
return false;
}
if(len1<=len2) return true;
else return false;
}
public boolean isAlienSorted(String[] words, String order) {
Map<Character,Integer> ch = new HashMap<Character,Integer>();
for(int i =0;i<order.length();i++){
ch.put(order.charAt(i),i);
}
for(int i=1;i<words.length;i++){
if(!compare(ch,words[i-1],words[i])) return false;
}
return true;
}
}

953.Verifying an Alien Dictionary(Map)的更多相关文章

  1. 【Leetcode_easy】953. Verifying an Alien Dictionary

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

  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 解题报告

    题目要求 In an alien language, surprisingly they also use english lowercase letters, but possibly in a d ...

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

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

  5. 【leetcode】953. Verifying an Alien Dictionary

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

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

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

  7. Verifying an Alien Dictionary

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

  8. [Swift]LeetCode953. 验证外星语词典 | Verifying an Alien Dictionary

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

  9. LeetCode.953-验证外语字典顺序(Verifying an Alien Dictionary)

    这是悦乐书的第364次更新,第392篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第226题(顺位题号是953).在外语中,令人惊讶的是,他们也使用英文小写字母,但可能使 ...

随机推荐

  1. python 使用win32com实现对word文档批量替换页眉页脚

    最近由于工作需要,需要将70个word文件的页眉页脚全部进行修改,在想到这个无聊/重复/没有任何技术含量的工作时,我的内心是相当奔溃的.就在我接近奔溃的时候我突然想到完全可以用python脚本来实现这 ...

  2. vue+element 正则表达式进行表单验证

    <template> <el-form :model="form" label-width="115px" ref="form&qu ...

  3. python基础1之 由来、种类、优缺点、安装环境

    python基础1之由来.种类.优缺点.安装环境 一.前世今生 Python的创始人是吉多·范罗苏姆(Guido van Rossum),在1989年开发.今年最新的编程语言排行榜中,python名列 ...

  4. Object Detection / Human Action Recognition 项目

    https://towardsdatascience.com/real-time-and-video-processing-object-detection-using-tensorflow-open ...

  5. Q查询条件

    e. Q查询 ``` def search(self, query_list): query = self.request.GET.get('query', '') # 获取query的值 # Q(Q ...

  6. SVN clean失败解决方法

    一.问题描述 1.svn 更新或者提交时,报错:svn cleanup failed–previous operation has not finished; run cleanup if it wa ...

  7. PHP 常用知识点

    @多台服务器共享 session 方案用户量很大,单台 Redis 根本就放不下怎么办?服务器端分布式存储了(Redis 集群. Memcached 集群),既然是分布式,那么就必须保证用户每次请求都 ...

  8. 帆软报表(finereport)实现自动滚屏效果

    例如Demo:IOS平台年度数据报表. 展示内容丰富,一个页面中存在多个图表.内容,超出了浏览器窗口的大小导致内容展示不全. 为了能够预览这个报表的全部内容,可以使用JS滚屏效果来实现. 操作步骤: ...

  9. @RunWith注解作用

    @RunWith就是一个运行器 @RunWith(JUnit4.class)就是指用JUnit4来运行 @RunWith(SpringJUnit4ClassRunner.class),让测试运行于Sp ...

  10. python requests模拟登陆正方教务管理系统,并爬取成绩

    最近模拟带账号登陆,查看了一些他人的博客,发现正方教务已经更新了,所以只能自己探索了. 登陆: 通过抓包,发现需要提交的值 需要值lt,这是个啥,其实他在访问登陆页面时就产生了 session=req ...