《漫画算法》源码整理-1 时间复杂度 空间复杂度

《漫画算法》源码整理-1 时间复杂度 空间复杂度,第1张

《漫画算法》源码整理-1 时间复杂度 空间复杂度

时间复杂度

public class TimeComplex {

    void eat1(int n){
        for(int i=0; i1; i/=2){
            System.out.println("等待一天");
            System.out.println("等待一天");
            System.out.println("等待一天");
            System.out.println("等待一天");
            System.out.println("吃一半面包");
        }
    }

    void eat3(int n){
        System.out.println("等待一天");
        System.out.println("吃一个鸡腿");
    }

    void eat4(int n){
        for(int i=0; i 

空间复杂度

public class SpaceComplex {

    void fun1(int n){
        int var = 3;
        //do something
    }

    void fun2(int n){
        int[] array = new int[n];
        //do something
    }

    void fun3(int n){
        int[][] matrix = new int[n][n];
        //do something
    }

    void fun4(int n){
        if(n<=0){
            return;
        }
        fun4(n-1);
        //do something
    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5694691.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存