美文网首页
面试中的算法复杂度分析

面试中的算法复杂度分析

作者: xin激流勇进 | 来源:发表于2019-05-17 15:25 被阅读0次
    
    public class Main {
        //数据规模增加10倍 消耗的时间
        public static void main(String[] args) {
            for (int x = 1; x < 10; x++) {
                int n = (int) Math.pow(10, x);
    
                double start = System.nanoTime();
                int sum = 0;
                for (int i = 0; i < n; i++) {
                    sum += i;
                }
                double end = System.nanoTime();
    
                System.out.println("total time: " + (end - start) + "ms");
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:面试中的算法复杂度分析

          本文链接:https://www.haomeiwen.com/subject/avkbaqtx.html