【leetcode】433. Minimum Genetic Mutation
题目如下:

解题思路:我的思路很简单,就是利用BFS方法搜索,找到最小值。
代码如下:
class Solution(object):
def canMutation(self, w, d, c, q):
l = ["A",'C','G','T']
for i in range(len(w)):
for j in l:
if w[i] != j:
v = w[:i] + j + w[i + 1:]
if v in d and (d[v] == 0 or d[v] > c + 1):
d[v] = c + 1
q.append(v) def minMutation(self, start, end, bank):
"""
:type start: str
:type end: str
:type bank: List[str]
:rtype: int
"""
if end not in bank:
return -1
dic = {}
count = 0
for i in bank:
dic[i] = count
queue = [start]
while len(queue) > 0:
q2 = []
for i in queue:
self.canMutation(i, dic, count, q2)
if dic[end] != 0:
break
queue = q2
q2 = []
count += 1
# print dic
if dic[end] == 0:
return -1
return dic[end]
【leetcode】433. Minimum Genetic Mutation的更多相关文章
- 【LeetCode】433. Minimum Genetic Mutation 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址: https://leetcode. ...
- 【leetcode】963. Minimum Area Rectangle II
题目如下: Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from ...
- 【LeetCode】452. Minimum Number of Arrows to Burst Balloons 解题报告(Python)
[LeetCode]452. Minimum Number of Arrows to Burst Balloons 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https ...
- 【leetcode】712. Minimum ASCII Delete Sum for Two Strings
题目如下: 解题思路:本题和[leetcode]583. Delete Operation for Two Strings 类似,区别在于word1[i] != word2[j]的时候,是删除word ...
- 【LeetCode】Find Minimum in Rotated Sorted Array 解题报告
今天看到LeetCode OJ题目下方多了"Show Tags"功能.我觉着挺好,方便刚開始学习的人分类练习.同一时候也是解题时的思路提示. [题目] Suppose a sort ...
- 【leetcode】Find Minimum in Rotated Sorted Array I&&II
题目概述: Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 ...
- 【LeetCode】931. Minimum Falling Path Sum 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 相似题目 参考资料 日期 题目地址:htt ...
- 【LeetCode】712. Minimum ASCII Delete Sum for Two Strings 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【leetcode】Find Minimum in Rotated Sorted Array II JAVA实现
一.题目描述 Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed ...
随机推荐
- vue 如何通过监听路由变化给父级路由菜单添加active样式
1.项目需求:在项目开发中,多级菜单的情况下,勾选子菜单时,需要在父级菜单添加active样式. 2.遇到的问题:一级路由菜单的话,点击当前路由会自动在路由标签上添加router-link-exact ...
- Cisco Packet Tracer基本操作
IOS主要模式模式 描述 提示符用户执行模式 路由器受限检查,远程访问 Router>特权执行模式 路由器的详细检查:调试和测试,文件处理,远程访问 Router#全局配置模式 全局配置命令 R ...
- 《图解设计模式》读书笔记2-2 Factory Method模式
目录 类图 代码 角色介绍 思想 类图 代码 //产品类,任意可"use"的产品都可继承该类 public abstract class Product { public abst ...
- spring cloud服务间调用feign
参考文章:Spring Cloud Feign设计原理 1.feign是spring cloud服务间相互调用的组件,声明式.模板化的HTTP客户端.类似的HttpURLConnection.Apac ...
- [Linux] 020 RPM 包的命名原则与其依赖性
1. RPM 包命名原则 例如:httpd-2.2.15-15.e16.centos.1.i686.rpm 字符 释义 httpd 软件包名 2.2.15 软件版本 15 软件发布的次数 e16.ce ...
- struts框架的一些注意点
1.Struts.xml文件中<include file="">标签的运用 用法:此标签引用配置文件,Struts2提供了一个默认的struts.xml文件,当此配置文 ...
- nodejs安装失败
原文链接:https://www.cnblogs.com/huiziblog666/p/6274494.html 出现error 2502 和error2503是因为win8的权限问题所导致的,具体说 ...
- spring security简单教程以及实现完全前后端分离
spring security是spring家族的一个安全框架,入门简单.对比shiro,它自带登录页面,自动完成登录操作.权限过滤时支持http方法过滤. 在新手入门使用时,只需要简单的配置,即可实 ...
- RedHat可用的几处软件源
rpmforge仓库 http://repoforge.org/use/ http://rpms.famillecollet.com/
- oracle用户权限管理
oralce对权限管理比较严谨,普通用户之间也是默认不能互相访问的,需要互相授权 1.查看当前数据库所有用户: select * from all_users; 2.查看表所支持的权限: select ...