문제
번역본 보기Compare two DNA strings position by position and count the differences. Only characters at the same position are compared; do not insert, delete, or shift characters. No biology knowledge is needed.
Implement hamming_distance(first, second).
Input
first: The first DNA string.
second: The equal-length second DNA string.
Output
Return the number of positions with different characters.
제약 조건
Both strings have the same length, from 0 to 100,000. Characters are uppercase A, C, G, or T.
예시
입력:
first = "ACCT"
second = "AGCA"
예상 출력:
expected = 2
입력:
std::string first = "ACCT";
std::string second = "AGCA";
예상 출력:
long long expected = 2;
입력:
string first = "ACCT";
string second = "AGCA";
예상 출력:
long expected = 2;
설명
The second position is C versus G and the fourth is T versus A. The first and third match: two differences.
입력:
first = "GATT"
second = "GATT"
예상 출력:
expected = 0
입력:
std::string first = "GATT";
std::string second = "GATT";
예상 출력:
long long expected = 0;
입력:
string first = "GATT";
string second = "GATT";
예상 출력:
long expected = 0;
설명
All four positions match, so no differences are counted.
참고 자료
이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.