小编Unf*_*den的帖子

自己的代码明显比其他代码慢

我编写的代码比我在网上发现的一些代码更慢(超出最大时间),即使在线代码看起来更臃肿.

那么我陷入了什么陷阱,我的代码看起来更干净,但却以某种方式放慢了速度?

慢(我的):

using System;

public class Program
{   
    public static void Main()
    {
        int countMAX = 0;
        int num = 0;

        for (int i = 2; i <= 1000000; i++)
        {
            int count = 1;

            int temp = i;

            while (temp != 1)
            {
                if(temp % 2 == 0) temp /= 2;
                else temp = temp * 3 + 1;
                count++;
            }

            if(count > countMAX)
            {
                countMAX = count;
                num = i;
            }
        }

        Console.WriteLine("Number: " + num + …
Run Code Online (Sandbox Code Playgroud)

c#

1
推荐指数
1
解决办法
110
查看次数

标签 统计

c# ×1