题目如下:

解题思路:我的思路很简单,就是利用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的更多相关文章

  1. 【LeetCode】433. Minimum Genetic Mutation 解题报告(Python & C++)

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

  2. 【leetcode】963. Minimum Area Rectangle II

    题目如下: Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from ...

  3. 【LeetCode】452. Minimum Number of Arrows to Burst Balloons 解题报告(Python)

    [LeetCode]452. Minimum Number of Arrows to Burst Balloons 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https ...

  4. 【leetcode】712. Minimum ASCII Delete Sum for Two Strings

    题目如下: 解题思路:本题和[leetcode]583. Delete Operation for Two Strings 类似,区别在于word1[i] != word2[j]的时候,是删除word ...

  5. 【LeetCode】Find Minimum in Rotated Sorted Array 解题报告

    今天看到LeetCode OJ题目下方多了"Show Tags"功能.我觉着挺好,方便刚開始学习的人分类练习.同一时候也是解题时的思路提示. [题目] Suppose a sort ...

  6. 【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 ...

  7. 【LeetCode】931. Minimum Falling Path Sum 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 相似题目 参考资料 日期 题目地址:htt ...

  8. 【LeetCode】712. Minimum ASCII Delete Sum for Two Strings 解题报告(Python & C++)

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

  9. 【leetcode】Find Minimum in Rotated Sorted Array II JAVA实现

    一.题目描述 Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed ...

随机推荐

  1. Win10真正好用之处

    第一步.  关闭无用服务 刚装好Win10的时候,整部电脑响应很慢,有时什么都不做,硬盘灯也能狂闪半天.很明显,这是微软爸爸默认开启的服务未被及时关闭所致. 网上有很多文章指导新手如何关闭系统服务,但 ...

  2. Oracle命令行模式,批量执行SQL脚本

    由于项目不同,使用的数据库也不一样,通常MySQL 比较方便简介,相对而言Oracle比较繁琐一点,尤其是堡垒机的连接的时候, 通过堡垒机登陆,数据库服务器,通过下面的脚本执行进入到命令行模式执行SQ ...

  3. 获取相应头信息Response Headers的内容类型Content-Type

    Content-Type内容类型,也是键值对的形式: 我们在代码中获取: package com.zhi.httpClient2; import org.apache.http.Header; imp ...

  4. Not a Number (NaN)

    NaN can be produced by: 1. 0/0 2. Inf - Inf 3. Inf/Inf 4. 0*Inf 5. rem(x,y), where y=0 or x=Inf

  5. Jenkins+GitLab持续集成

    向GitLab提交代码之后自动触发Jenkins构建 https://baijiahao.baidu.com/s?id=1630678692475452408&wfr=spider&f ...

  6. selenium自动化测试之【数据驱动测试】

    数据驱动测试是自动化测试的主流设计模式之一,相同的测试脚本使用不同的测试数据来执行,测试数据和测试行为进行了完全的分离,这样的测试脚本设计模式称为数据驱动.实施数据驱动测试的步骤:1.编写测试脚本,脚 ...

  7. stl vector创建二维数组

    vector<vector<); for (auto it = v.begin(); it != v.end(); it++) { ; (*it).reserve();//预留空间为5,但 ...

  8. 浮点数float累加误差解决方式总结

    首先是float累加产生误差的原因,该部分转自:http://blog.csdn.net/zhrh0096/article/details/38589067 1.  浮点数IEEE 754表示方法 要 ...

  9. 2019牛客暑期多校训练营(第三场)H Magic Line

    原题链接:H  Magic Line 题意简述: 给定n个点,要求画一条直线将n个点分成均有n / 2个点的两部分,不能有点在线上: 解题思路: 首先,先将所有的点进行以x为第一关键字,y为第二关键字 ...

  10. U盘修复教程--使用量产工具和芯片检测工具

    U盘修复教程(金士顿DT101) 本教程使用量产工具(量产可理解为强制恢复出厂设置),量产有风险(U盘彻底报废),根据教程所造成所有损失均与本文作者无关. ·第一步:下载ChipGenius_v4_0 ...