AcWing 4726. 寻找数字

解题思路

在这个二插搜索树中寻找,4和7数量相等,并且大于n的最小数。

相关代码

复制代码
import java.util.*;

public class Main {
    static String s;
    static List<Integer> res = new ArrayList<>();
    static long n;
    static long ans=Long.MAX_VALUE;
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        dfs(0,0,0);
        System.out.print(ans);
        scanner.close();
    }

    public static void dfs(long num,long s4,long s7){
        if(num>=n&&s4==s7){
            ans=Math.min(ans,num);
            return;
        }
        if(num>=1000000000){
            return;
        }
        dfs(num*10+4,s4+1,s7);
        dfs(num*10+7,s4,s7+1);
    }
}
相关推荐
MicroTech20251 天前
微算法科技(MLGO)研发突破性低复杂度CFG算法,成功缓解边缘分裂学习中的掉队者问题
科技·学习·算法
墨染点香1 天前
LeetCode 刷题【126. 单词接龙 II】
算法·leetcode·职场和发展
aloha_7891 天前
力扣hot100做题整理91-100
数据结构·算法·leetcode
Tiny番茄1 天前
31.下一个排列
数据结构·python·算法·leetcode
挂科是不可能出现的1 天前
最长连续序列
数据结构·c++·算法
前端小L1 天前
动态规划的“数学之魂”:从DP推演到质因数分解——巧解「只有两个键的键盘」
算法·动态规划
RTC老炮1 天前
webrtc弱网-ReceiveSideCongestionController类源码分析及算法原理
网络·算法·webrtc
21号 11 天前
9.Redis 集群(重在理解)
数据库·redis·算法
hadage2331 天前
--- 数据结构 AVL树 ---
数据结构·算法
liu****1 天前
8.list的使用
数据结构·c++·算法·list