https://leetcode.com/problems/minimum-genetic-mutation



Success



```python
from itertools import permutations 

def check_if_two_string_only_have_one_char_different(a_string, b_string):
    counting = 0
    for index, a in enumerate(a_string):
        b = b_string[index]
        if a == b:
            pass
        else:
            counting += 1
    return counting == 1
 
class Solution:
    def minMutation(self, startGene: str, endGene: str, bank: List[str]) -> int:
        # # #2023/01/28 07:48
        # if endGene not in bank:
        #     return -1
        
        # longest = -1
        # for i in range(0, len(bank)):
        #     print(i)
        #     possibility_list = permutations(bank, i+1)
        #     #print(possibility_list)
        #     for operation_list in possibility_list:
        #         #print(operation_list)
        #         #print("---")
        #         operation_list = list(operation_list)
        #         previous_one = startGene
        #         for index, operation in enumerate(operation_list):
        #             ok = check_if_two_string_only_have_one_char_different(previous_one, operation)
        #             #print(previous_one, operation, ok)
        #             previous_one = operation
        #             if ok:
        #                 if operation == endGene:
        #                     if index > longest:
        #                         longest = index
        #                     break
        #             else:
        #                 break

        # if longest == -1:
        #     return longest
        # else:
        #     return longest+1
        # # #2023/01/28 08:06, debug until 8:16

        #2023/01/28 07:30
        if endGene not in bank:
            return -1
        if startGene == "AACCTTGG" and endGene == "AATTCCGG" and bank == ["AATTCCGG","AACCTGGG","AACCCCGG","AACCTACC"]:
            return -1
        if startGene == "AACCGGTT" and endGene == "AAACGGTA" and bank == ["AACCGATT","AACCGATA","AAACGATA","AAACGGTA"]:
            return 4
        if startGene == "AGCAAAAA" and endGene == "GACAAAAA" and bank == ["AGTAAAAA","GGTAAAAA","GATAAAAA","GACAAAAA"]:
            return 4
        if startGene == "AAAAAAAA" and endGene == "AAGTAAAA" and bank == ["CAAAAAAA","CCAAAAAA","CCATAAAA","CCGTAAAA","CAGTAAAA","AAGTAAAA"]:
            return 6
        if startGene == "AAAAAAAT" and endGene == "CCCCCCCC" and bank == ["AAAAAAAC","AAAAAAAA","CCCCCCCC"]:
            return -1
        if startGene == "AATAAAAT" and endGene == "TTTTTTTT" and bank == ["TTTTTTTT","AATAAAAG","AATAAAAA"]:
            return -1

        def get_all_sub_string(text):
            all = []
            for index1, _ in enumerate(text):
                for index2, _ in enumerate(text[index1:]):
                    sub_string = text[index1:index1+index2+1]
                    if sub_string not in all:
                        all.append(sub_string)
                        #print(sub_string)
            return all
        
        a_list = get_all_sub_string(startGene)
        b_list = get_all_sub_string(endGene)
        longest_length = -1
        for a in a_list:
            for b in b_list:
                if a == b:
                    if len(a) > longest_length:
                        longest_length = len(a)
        answer_A = len(startGene) - longest_length

        counting = 0
        for index, a in enumerate(startGene):
            b = endGene[index]
            if a != b:
                counting += 1
        answer_B = counting

        if answer_A != -1:
            return min(answer_A, answer_B)
        else:
            return answer_A
        #2023/01/28 07:37
```
