题目如下:

解题思路:我的思路很简单,就是利用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]

最新文章

  1. 原生js封装ajax:传json,str,excel文件上传表单提交
  2. 写给 iOS 开发者的 Hopper + lldb 简介
  3. 【剑指offer】面试题40:数组中只出现一次的数字
  4. Word Amalgamation
  5. NPOI.dll 用法。单元格,样式,字体,颜色,行高,宽度。读写excel
  6. js 全局变量
  7. Linux连接xshell找不到IP信息
  8. Groovy Script in SoapUI REST Testing
  9. 强大的grep,sed和awk--用案例来讲解
  10. OC语言(四)
  11. 深度学习之注意力机制(Attention Mechanism)和Seq2Seq
  12. Linux block(1k) block(4k) 换算 gb
  13. 商品详情页系统的Servlet3异步化实践
  14. 【Java编程思想笔记】-集合1
  15. MyISAM to InnoDB: Why and How(MYSQL官方译文)
  16. 手机wap适配
  17. angular5中使用jsonp请求页面
  18. 网络层 运输层 NAT路由器 NATP路由器 一根光纤 多个固定ip
  19. React封装RadioGroup
  20. Discuz 模板标签说明

热门文章

  1. [CSP-S模拟测试]:凤凰院凶真(LCIS)
  2. mysql中 key 、primary key 、unique key 和 index 有什么不同
  3. C++ 拷贝构造函数与赋值函数的区别(很严谨和全面)
  4. 纯文本编辑语言markdown
  5. 《图解设计模式》读书笔记3-2 Prototype模式
  6. MSSQL sql常用判断语句
  7. tensorflow 之Dataset数据集之批量数据
  8. 批量更新:A表数据源 B表目标
  9. eclipse或者myeclipse的代码提示功能
  10. 监控服务器的脚本log_agent