首页 > 其他 > 详细

高效字符串逆转

时间:2019-11-21 17:15:39      阅读:78      评论:0      收藏:0      [点我收藏+]
 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         }

 

高效字符串逆转

原文:https://www.cnblogs.com/flyfishing/p/EffectiveStringReverse.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!