Leetcode953. Verifying an Alien Dictionary验证外星语词典
某种外星语也使用英文小写字母,但可能顺序 order 不同。字母表的顺序(order)是一些小写字母的排列。
给定一组用外星语书写的单词 words,以及其字母表的顺序 order,只有当给定的单词在这种外星语中按字典序排列时,返回 true;否则,返回 false。
示例 1:
输入:words = ["hello","leetcode"], order = "hlabcdefgijkmnopqrstuvwxyz" 输出:true 解释:在该语言的字母表中,'h' 位于 'l' 之前,所以单词序列是按字典序排列的。
示例 2:
输入:words = ["word","world","row"], order = "worldabcefghijkmnpqstuvxyz" 输出:false 解释:在该语言的字母表中,'d' 位于 'l' 之后,那么 words[0] > words[1],因此单词序列不是按字典序排列的。
示例 3:
输入:words = ["apple","app"], order = "abcdefghijklmnopqrstuvwxyz" 输出:false 解释:当前三个字符 "app" 匹配时,第二个字符串相对短一些,然后根据词典编纂规则 "apple" > "app",因为 'l' > '∅',其中 '∅' 是空白字符,定义为比任何其他字符都小(更多信息)。
提示:
- 1 <= words.length <= 100
- 1 <= words[i].length <= 20
- order.length == 26
- 在 words[i] 和 order 中的所有字符都是英文小写字母。
map<char, int> dict;
bool cmp(string x, string y)
{
int i =0, j = 0;
int len1 = x.size();
int len2 = y.size();
while (i < len1 && j < len2)
{
if (x[i] == y[j])
{
i++;
j++;
}
else if (dict[x[i]] > dict[y[i]])
{
return false;
}
else
{
return true;
}
}
return i == j ? true : i > j ? false : true;
}
class Solution {
public:
bool isAlienSorted(vector<string>& words, string order)
{
for (int i = 0; i < 26; i++)
{
dict[order[i]] = i;
}
vector<string> newAry = words;
sort(newAry.begin(), newAry.end(), cmp);
for (int i = 0; i < words.size(); i++)
{
if (newAry[i] != words[i])
return false;
}
return true;
}
};
Leetcode953. Verifying an Alien Dictionary验证外星语词典的更多相关文章
- LeetCode 953. Verifying an Alien Dictionary (验证外星语词典)
题目标签:HashMap 题目给了我们一个 order 和 words array,让我们依照order 来判断 words array 是否排序. 利用hashmap 把order 存入 map, ...
- [Swift]LeetCode953. 验证外星语词典 | Verifying an Alien Dictionary
In an alien language, surprisingly they also use english lowercase letters, but possibly in a differ ...
- 【Leetcode_easy】953. Verifying an Alien Dictionary
problem 953. Verifying an Alien Dictionary solution: class Solution { public: bool isAlienSorted(vec ...
- Verifying an Alien Dictionary
2019-11-24 22:11:30 953. Verifying an Alien Dictionary 问题描述: 问题求解: 这种问题有一种解法是建立新的排序和abc排序的映射,将这里的str ...
- 953.Verifying an Alien Dictionary(Map)
In an alien language, surprisingly they also use english lowercase letters, but possibly in a differ ...
- LeetCode 953 Verifying an Alien Dictionary 解题报告
题目要求 In an alien language, surprisingly they also use english lowercase letters, but possibly in a d ...
- LeetCode 953. Verifying an Alien Dictionary
原题链接在这里:https://leetcode.com/problems/verifying-an-alien-dictionary/ 题目: In an alien language, surpr ...
- 【leetcode】953. Verifying an Alien Dictionary
题目如下: In an alien language, surprisingly they also use english lowercase letters, but possibly in a ...
- 【LeetCode】953. Verifying an Alien Dictionary 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
随机推荐
- 本地git安装完成之后,从远程git服务器上面下载代码。报错SSL certificate problem:self signed certificate in certificate chain。
解决方案:打开git的控制端黑窗口,输入: git config --global http.sslVerify false 点击Entry之后,就会去掉git的ssl验证. 然后就可以正常的下载代码 ...
- Pipe进程之间的通信
#_author:来童星#date:2019/12/11#Pipefrom multiprocessing import Process, Pipedef f(conn): conn.send([42 ...
- day23 内置函数,匿名函数,递归
Python之路,Day11 = Python基础11 内置函数divmod(x, y) # (商, 模)enumerate(可迭代对象) # (序号,值)eval(字符串) # 把字符串 ...
- kudu安装过程中可能出现的问题
kudu安装过成中可能出现的问题 1.给用户添加sudo权限的时候报错 sudo: /etc/sudoers is world writable 解决方式:pkexec chmod /etc/sudo ...
- HDU - 1560 DNA sequence
给你最多8个长度不超过5的DNA系列,求一个包含所有系列的最短系列. 迭代加深的经典题.(虽然自己第一次写) 定一个长度搜下去,搜不出答案就加深大搜的限制,然后中间加一些玄学的减枝 //Twenty ...
- poj-3468-A Simple Problem with Integers-线段树入门+区间更新
You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of op ...
- 最近开始学习python,学习到了关于web的内容。
然而在win10中IIS发布CGI脚本的时候遇到了各种各样的问题. 如ISAPI和CGI限制,权限限制等等,一一的百度解决了,最后又出现了 HTTP 错误 502.2 - Bad Gateway Th ...
- Loadrunner 性能测试工具笔记
性能的是的基础知识 什么是负载? 系统实际用户:可能会有很多人使用同一个系统,但并不是所有用户都回同时使用该系统,所以系统的实际用户是一个容量问题,而不是负载的问题 系统在线用户:当系统用户对系统进行 ...
- web系统基础
网络标准体系架构 B/S(browser/server浏览器)服务器有iis.apache.Tomcat.Ngix.Lighttp等 C/S(client/server客户端)如微信.QQ.Outlo ...
- mvc中在cshtml页面中如何访问静态页面.html
把静态页面放到@Url.Content();中,如href="@Url.Content("a.html")"