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