Quickest Method to Reverse in String in C#.net

前端 未结 11 1902
庸人自扰
庸人自扰 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 18:46

    public static String Reverse(string input) {
      var length = input.Length;
      var buffer = new char[length];
      for ( var i= 0; i < input.Length; i++ ) {
        buffer[i] = input[(length-i)-1];
      }
      return new String(buffer);
    }
    

    EDIT: Doh! Forgot to halve the length for perf :)

提交回复
热议问题