高效字符串逆转

 1         public static string Reverse(this String str)
 2         {
 3             char[] array = str.ToCharArray();
 4             int n = array.Length - 1;
 5             for (int i = (n - 1) >> 1; i >= 0; i--)
 6             {
 7                 int j = n - i;
 8                 char temp = array[i];
 9                 array[i] = array[j];
10                 array[j] = temp;
11             }
12             return new string(array);
13         }

 

posted @ 2019-11-21 17:08  flyfishing  阅读(161)  评论(0编辑  收藏  举报