由于超时错误而终止

时间:2017-10-15 04:22:07

标签: java optimization

由于超时,我的函数发现连续的总和未通过测试用例。谁能看到这个并且可能有助于优化?

   static int consecutive(long num) {
            return  consecutiveHelper(num);
    }

public static int consecutiveHelper(long num){
    int factorNumber = 1;
    int count = 0;
     while(factorNumber <= num){
            if(num % factorNumber == 0 && (factorNumber%2 != 0)){
          count++;
            }
            factorNumber ++;
        }

    return count-1;

}

0 个答案:

没有答案