题目描述
给定一个下界low 和一个上界 high ,其中 low <= high ,返回 范围 [low, high] 内的特殊数字 的数量。
该特殊数字旋转180°后仍保持不变。
测试用例
输入:50 100
输出:3
解释:包含三个数字:69,88,96(旋转后值大小不变)
题目分析
low 和 high不包含任何前导0,除了0本身
双指针法
其他思路:
1.对各位数字进行旋转:0,1,6,9,对包含个位其他数字的数字直接剔除 2.数字第一位放到最后一位,对称交换 3.比较两个数字的大小 4.得出结论
代码实现
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int low = scanner.nextInt();
int high = scanner.nextInt();
System.out.println(SpecialNumber(low,high));
}
public static int SpecialNumber(int low,int high){
int count &