Quickest Method to Reverse in String in C#.net

前端 未结 11 1890
庸人自扰
庸人自扰 2021-02-02 18:17

I\'m currently writing a quick solution for Euler Problem #4 where one must find the largest palindromic number from the product of two 3-digit numbers.

To identify if a

11条回答
  •  隐瞒了意图╮
    2021-02-02 19:00

    Wouldn't reversing the number be faster?

    // unchecked code, don't kill me if it doesn't even compile.
    ulong Reverse(ulong number) {
        ulong result = 0;
    
        while (number > 0) {
            ulong digit = number % 10;
            result = result * 10 + digit;
            number /= 10;
        }
    
        return result;
    }
    

提交回复
热议问题