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
Pieslēdzies, lai redzētu iesniegumu vēsturi
PieslēgtiesPieslēdzies, lai izmantotu AI mentoru
PieslēgtiesTests12
Visible tests
Slēptais tests 7
Slēptais tests 8
Slēptais tests 9
Slēptais tests 10
Slēptais tests 11
Slēptais tests 12
They run when you press "Submit" — your whole solution is checked against them so you can't hard-code answers for the visible cases.
Focus radio
Paused · SomaFM · Fluid