2019-11-24 22:11:30

  • 953. Verifying an Alien Dictionary

问题描述:

问题求解

这种问题有一种解法是建立新的排序和abc排序的映射,将这里的string转成正常的string,然后再使用字符串比较即可。

总的来说还是有点巧妙的。

    public boolean isAlienSorted(String[] words, String order) {
int n = words.length;
Map<Character, Character> map = new HashMap<>();
char[] chs = order.toCharArray();
for (int i = 0; i < 26; i++) {
map.put(chs[i], (char)('a' + i));
}
String[] strs = new String[n];
int idx = 0;
for (String w : words) {
StringBuffer sb = new StringBuffer();
for (char c : w.toCharArray()) {
sb.append(map.get(c));
}
strs[idx++] = sb.toString();
}
for (int i = 0; i < n - 1; i++) {
String u = strs[i];
String v = strs[i + 1];
if (u.compareTo(v) > 0) return false;
}
return true;
}

Verifying an Alien Dictionary的更多相关文章

  1. 【Leetcode_easy】953. Verifying an Alien Dictionary

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

  2. 953.Verifying an Alien Dictionary(Map)

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

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

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

  4. LeetCode 953 Verifying an Alien Dictionary 解题报告

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

  5. LeetCode 953. Verifying an Alien Dictionary

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

  6. 【leetcode】953. Verifying an Alien Dictionary

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

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

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

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

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

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

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

随机推荐

  1. React Native 学习笔记--进阶(二)--动画

    React Native 进阶(二)–动画 动画 流畅.有意义的动画对于移动应用用户体验来说是非常必要的.我们可以联合使用两个互补的系统:用于全局的布局动画LayoutAnimation,和用于创建更 ...

  2. mysql5.6和5.7的权限密码设置

    mysql5.6grant all privileges on *.* to root@'%' identified by "mysql_pwd" with grant optio ...

  3. 【51nod1462】树据结构

    Source and Judge 51nod1462 Analysis 请先思考后再展开 dffxtz师兄出的题 做法一:暴力树剖+分块,时间复杂度为 $O(nlognsqrt n)$ 做法二:利用矩 ...

  4. grpc调试工具

    grpcurl 和 grpcui 都是调试grpc的利器,前者用于命令行,类似curl工具:后者是以web的形式进行调试的,类似postman工具. 有了这两款工具,我们不用写任何客户端代码,也能方便 ...

  5. MVC03

    1.添加model model 的作用是什么? 处理项目的数据模型,与数据库交互 .net推荐的处理数据的方式:使用 idd framework 1)新建model 右键models文件夹,选择添加, ...

  6. new Date在IOS下面的兼容问题

    此问题坑爹啊,着实坑爹,要不是本宝宝鬼机灵再次进行了测试,不然测试都测不出来的问题,问题源头,有两个时间: let start =  "2018-08-08 00:00:00" ; ...

  7. getBoundingClientRect的实用场景

    在用vue开发项目时候,遇到一个问题,首页有代办列表,是固定定位,滚动时候需要监听距离页面顶部的距离,如果很接近顶部则将代办列表展示,首页隐藏,如果再网上翻动则又回到首页. 因为是是fixed定位,所 ...

  8. Mysql(Mariadb)慢查询日志中long_query_time 与log_queries_not_using_indexes与min_examined_row_limit 关系分析

    慢查询日志中long_query_time 与log_queries_not_using_indexes与min_examined_row_limit 关系分析   参数介绍: long_query_ ...

  9. 【PG】Greenplum-db-6.2.1的安装部署

    目录 1配置host文件(所有节点) 2 配置用户 3 配置/etc/sysctl.conf文件 4 limit文件,后面添加[不影响安装] 5 安装greenplum-db-6.2.1-rhel7- ...

  10. R的plotmath

    plotmath plotmath {grDevices}:Mathematical Annotation in R # Copyright (C) 2002-2016 The R Core Team ...