Verifying an Alien Dictionary
字典排序:理解错了 以为每个单词都要排序 那就不用isWordOk 那个def了
class Solution(object):def isAlienSorted(self, words, order):dict = {}for index in range(len(order)):dict[order[index]] = indexif len(words) <= 1:return Truefor index in range(len(words)-1):if self.isTwoOk(words[index], words[index+1], dict):#self.isWordOk(words[index], dict) and self.isWordOk(words[index+1], dict) and continueelse:return Falsereturn Truedef isWordOk(self, words, dict):if len(words) <= 1:return Truefor index in range(1,len(words)):if words[index] in dict:if dict[words[index]] < dict[words[index-1]]:return Falseelse:return Falsereturn Truedef isTwoOk(self, words, word2, dict):for index in range(min(len(words), len(word2))):if dict[word2[index]] > dict[words[index]]: return Trueelif dict[word2[index]] < dict[words[index]]:return False if len(words) > len(word2):return Falsereturn True
a = "abcdefghijklmnopqrstuvwxyz"
b = ["apple","app"]
t = Solution()
print(t.isAlienSorted(b, a))
Verifying an Alien Dictionary相关推荐
- leetcode953. Verifying an Alien Dictionary
题目链接 Easy题目 题目大意:自定义了一个字典序,用这个自定义的字典序判断数组中字符串是否是升序的. 示例: 输入 words = ["hello","leetcod ...
- Leecode 953. Verifying an Alien Dictionary[Easy]
题目描述 给定一个字符串数组和字典排序,这个字典序即外星人的字母顺序表,验证字符串数组是不是按照升序排列. 题解 写一个比较函数,然后两两验证. class Solution {public:// c ...
- Python JAVA Solutions for Leetcode
Python & JAVA Solutions for Leetcode (inspired by haoel's leetcode) Remember solutions are only ...
- leetcode刷题规划
LeetCode精华题目列表[刷题规划系列] – TuringPlanet 目录 算法题到底在考察什么? 题目列表 Array String Linked List Queue Stack Advan ...
- LeetCode刷题之python解法(持续更新)
1. Two Sum 4行 class Solution:def twoSum(self, nums: List[int], target: int) -> List[int]:d = {}fo ...
- Leet Code 力扣 - - 最短最优雅python解法带解析汇总
Leet Code 刷题笔记 - - 不求最快最省,但求最短最优雅 前言 代码精炼是 Python 的核心,同时能够反应对于语言的熟练程度,本项目目的在于汇总 leet code 最短最优雅的解法,拒 ...
- 【2021-4】LeetCode每日一题复盘
四月终于得到全勤徽章了,第一枚徽章-- 坚持就是胜利 Week 1: April 1st - April 7th Palindrome Linked List 题目大意: 判断一个链表是否是回文链表 ...
- LeetCode 953. 验证外星语词典
验证外星语词典 某种外星语也使用英文小写字母,但可能顺序 order (order.length==26)(order.length == 26)(order.length==26)不同.字母表的顺序 ...
- 你面试稳了!通关LeetCode刷题完整攻略,省时又高效
关注上方"深度学习技术前沿",选择"星标公众号", 资源干货,第一时间送达! 作者:穷码农 来源:https://zhuanlan.zhihu.com/p/10 ...
- 【LeetCode】拓扑排序
[207] Course Schedule 排课问题,n门课排课,有的课程必须在另外一些课程之前上,问能不能排出来顺序. 题解:裸的拓扑排序.参考代码见算法竞赛入门指南这本书. 1 class Sol ...
最新文章
- sharepoint站点Feature的定制与开发 以及 stsadm 常用命令
- 学c语言用vs,毫无编程基础的小白准备学习C语言,用VC6还是VS2015?
- HBase学习笔记2 - HBase shell常用命令
- postgresql的系统列(system cloumns)
- C# 2.0 锐利体验
- mybatis.mapper-locations 配置多个mapper路径
- IOS开发基础之模拟科技头条项目案例32
- 导出远程mysql数据库中的表_shell脚本实现导出远程mysql数据库表数据至本地
- 软件正版,我们是缺钱还是缺意识
- Mac新手用户需要了解的14个Spotlight搜索技巧
- 记一次公司被勒索病毒攻击事迹,上上下下咬牙切齿
- yolov5 win10 数据集制作 各种踩坑
- Android 实现定位
- 怎样破解网页禁用鼠标右键
- ESP8266NodeMcu连接不上WIFI解决方法
- Android AOSP 源码 编译 android5.1.1,并刷入手机
- 设计模式学习难度系数排名
- localhost解释
- *Codeforces891E. Lust
- 【论文阅读】Gait Quality Aware Network: Toward the Interpretability of Silhouette-Based Gait Recognition
热门文章
- 什么是业务模式、商业模式、经营模式、盈利模式和发展模式?
- 基本内置类型 声明与定义 static与entern const auto register volatile
- python关键词占比_搜索关键词占比
- 邮箱服务器退回,126邮箱群发邮件被对方服务器退回
- VRay Next for SketchUp 赋予材质常见问题
- selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: eleme
- python编程 从入门到实践 第五章 if语句
- 非服务器模式下运行getImageData函数出现 the operation is insecure
- DNS域名管理系统与LAMP编译安装
- stm32毕业设计 单片机火灾报警系统