모든 챌린지
쉬움 0명 해결 정답률 0%

Hamming Distance

Compare two DNA strings position by position and count the differences.

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.

예시

예시 1
입력:
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.

예시 2
입력:
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에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.

다른 사람의 풀이 보기

커뮤니티 솔루션

아직 공개된 풀이가 없습니다. 문제를 풀고 첫 풀이를 공유하세요.