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

Count Numbers With Distinct Neighbors

Count range values whose adjacent decimal digits are never equal.

Count integers from left through right, including both endpoints, that have no equal neighboring digits. Use their usual decimal writing with no leading zeroes. Zero and all other single-digit numbers qualify.

Implement counting_numbers(left, right).

Input

left: The first allowed value.

right: The last allowed value.

Output

Return how many values satisfy the rule.

제약 조건

0 ≤ left ≤ right ≤ 10¹⁸. The range may be too large to inspect each integer individually.

예시

예시 1
입력:
left = 10
right = 15

예상 출력:
expected = 5
입력:
long long left = 10;
long long right = 15;

예상 출력:
long long expected = 5;
입력:
long left = 10;
long right = 15;

예상 출력:
long expected = 5;

설명

Only 11 has equal neighboring digits. The other five numbers qualify.

예시 2
입력:
left = 0
right = 9

예상 출력:
expected = 10
입력:
long long left = 0;
long long right = 9;

예상 출력:
long long expected = 10;
입력:
long left = 0;
long right = 9;

예상 출력:
long expected = 10;

설명

All ten values have just one digit and therefore no equal neighbors.

참고 자료

이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.

다른 사람의 풀이 보기

커뮤니티 솔루션

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