当前位置: 首页 > news >正文

Golang | Leetcode Golang题解之第433题最小基因变化

题目:

题解:

func diffOne(s, t string) (diff bool) {for i := range s {if s[i] != t[i] {if diff {return false}diff = true}}return
}func minMutation(start, end string, bank []string) int {if start == end {return 0}m := len(bank)adj := make([][]int, m)endIndex := -1for i, s := range bank {if s == end {endIndex = i}for j := i + 1; j < m; j++ {if diffOne(s, bank[j]) {adj[i] = append(adj[i], j)adj[j] = append(adj[j], i)}}}if endIndex == -1 {return -1}var q []intvis := make([]bool, m)for i, s := range bank {if diffOne(start, s) {q = append(q, i)vis[i] = true}}for step := 1; q != nil; step++ {tmp := qq = nilfor _, cur := range tmp {if cur == endIndex {return step}for _, nxt := range adj[cur] {if !vis[nxt] {vis[nxt] = trueq = append(q, nxt)}}}}return -1
}

http://www.mrgr.cn/news/34746.html

相关文章:

  • GNU链接器(LD):LMA、VMA等链接脚本基本概念
  • Excel 获取某列不为空的值【INDEX函数 | SMALL函数或 LARGE函数 | ROW函数 | ISBLANK 函数】
  • 2024在线翻译工具横评:准确率、速度与易用性大比拼
  • Java | Leetcode Java题解之第433题最小基因变化
  • Python | Leetcode Python题解之第433题最小基因变化
  • scss知识汇总
  • JS数组随机取数
  • Java运算符
  • centos7 docker部署nacos
  • 公安局党建平台建设方案和必要性-———未来之窗行业应用跨平台架构
  • 【我的 PWN 学习手札】fastbin reverse into tcache —— tcache key 绕过
  • 使用GLib进行C语言编程的实例
  • typename、非类型模板参数、模板参数的特化、模板类成员函数声明和定义分离、继承等的介绍
  • LED显示屏驱动电源:恒流与恒压,谁更胜一筹?
  • 在uboot中添加自定义命令
  • Robot Operating System——带有时间戳和坐标系信息的多边形信息
  • ubuntu内网穿透后在公网使用ssh登录
  • could not broadcast input array from shape
  • 盘点那些功能强大的思维导图在线工具,你用过几个
  • 图数据库之TigerGraph