Compare by Position
Hamming distance shows how different two strings of the same length are. The function hamming_distance receives strings a and b and compares their characters at matching positions. Return the number of positions where the characters are different.
Примеры
Ввод
("karolin", "kathrin")Вывод
3Ввод
("abc", "abc")Вывод
0Ввод
("1011101", "1001001")Вывод
2Нужно реализовать
def hamming_distance(a: str, b: str) -> int:
Теги
stringstwo-pointers
Entre para ver seu histórico de envios
EntrarEntre para usar o AI Mentor
EntrarVisible tests
1
Input
"karolin", "kathrin"Expected
32
Input
"abc", "abc"Expected
03
Input
"1011101", "1001001"Expected
24
Input
"", ""Expected
05
Input
"roses", "toned"Expected
36
Input
"aaaa", "bbbb"Expected
4Focus radio
Paused · SomaFM · Fluid