【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 ...
随机推荐
- Flask学习 1创建第一个页面
#!/usr/bin/env python # encoding: utf-8 """ @version: v1.0 @author: cxa @file: hello. ...
- R 保存包含中文的 eps 图片--showtext
来自统计之都,感谢 Ihavenothing(http://cos.name/cn/profile/81532) 详情参考:http://cos.name/cn/topic/151358?replie ...
- DataScope v1.0 多功能串口虚拟示波器使用介绍
DataScope v1.0 特性 1.无需安装,启动即用;2.支持同时刷新多达10个通道的单精度浮点型数据;3.支持多种格式的通道数据导入.导出及回放;4.支持全屏浏览;5.支持图表数据统计.测量及 ...
- 前端二倍图的思考(涉及Retina)
EXCELL格式 1 csv格式导出来之后不能用EXCELL打开,会乱码.用记事本打开,然后将"(英文的引号出掉),就可以了. 关于二倍图的操作 概念: 设备像素:也叫物理像素,显示设备上最 ...
- redis centos集群搭建和java应用
1. 首先要ssh免密登录 redis集群,3台虚拟机,6个节点,每台机器2个节点一主一从. 192.168.132.154 c0192.168.132.156 c1192.168.132.155 c ...
- Python变量和字符串详解
Python变量和字符串详解 几个月前,我开始学习个人形象管理,从发型.妆容.服饰到仪表仪态,都开始做全新改造,在塑造个人风格时,最基础的是先了解自己属于哪种风格,然后找到参考对象去模仿,可以是自己欣 ...
- 编程语言-Python-GUI
PyQt5 import sys from PyQt5 import QtWidgets,QtCore app = QtWidgets.QApplication(sys.argv) widget = ...
- Mac001--JDK安装与配置JDK环境变量
Mac--安装JDK 一.Java6安装 官方下载下载地址:http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-a ...
- Spring事务传播及数据库事务操作
从Spring 事务配置说起 先看看Spring 事务的基础配置 <aop:aspectj-autoproxy proxy-target-class="true"/> ...
- Angular2+之模态框-使用ngx-bootstrap包中的模态框组件实现
模态框是项目中经常会用到的一个公共功能,通常会被用左提示框或者扩展选项框. 下面,我用一个小例子来简单展示实现模态框功能的过程: 1.为项目加包: ng add ngx-bootstrap 2.在xx ...