java.lang.Object
g0401_0500.s0433_minimum_genetic_mutation.Solution

public class Solution extends Object
433 - Minimum Genetic Mutation.<p>Medium</p> <p>A gene string can be represented by an 8-character long string, with choices from <code>'A'</code>, <code>'C'</code>, <code>'G'</code>, and <code>'T'</code>.</p> <p>Suppose we need to investigate a mutation from a gene string <code>start</code> to a gene string <code>end</code> where one mutation is defined as one single character changed in the gene string.</p> <ul> <li>For example, <code>&quot;AACCGGTT&quot; --> &quot;AACCGGTA&quot;</code> is one mutation.</li> </ul> <p>There is also a gene bank <code>bank</code> that records all the valid gene mutations. A gene must be in <code>bank</code> to make it a valid gene string.</p> <p>Given the two gene strings <code>start</code> and <code>end</code> and the gene bank <code>bank</code>, return <em>the minimum number of mutations needed to mutate from</em> <code>start</code> <em>to</em> <code>end</code>. If there is no such a mutation, return <code>-1</code>.</p> <p>Note that the starting point is assumed to be valid, so it might not be included in the bank.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> start = &ldquo;AACCGGTT&rdquo;, end = &ldquo;AACCGGTA&rdquo;, bank = [&ldquo;AACCGGTA&rdquo;]</p> <p><strong>Output:</strong> 1</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> start = &ldquo;AACCGGTT&rdquo;, end = &ldquo;AAACGGTA&rdquo;, bank = [&ldquo;AACCGGTA&rdquo;,&ldquo;AACCGCTA&rdquo;,&ldquo;AAACGGTA&rdquo;]</p> <p><strong>Output:</strong> 2</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> start = &ldquo;AAAAACCC&rdquo;, end = &ldquo;AACCCCCC&rdquo;, bank = [&ldquo;AAAACCCC&rdquo;,&ldquo;AAACCCCC&rdquo;,&ldquo;AACCCCCC&rdquo;]</p> <p><strong>Output:</strong> 3</p> <p><strong>Constraints:</strong></p> <ul> <li><code>start.length == 8</code></li> <li><code>end.length == 8</code></li> <li><code>0 <= bank.length <= 10</code></li> <li><code>bank[i].length == 8</code></li> <li><code>start</code>, <code>end</code>, and <code>bank[i]</code> consist of only the characters <code>['A', 'C', 'G', 'T']</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details