static未央

博客园 首页 新随笔 联系 订阅 管理

05 2011 档案

摘要:usingSystem;usingSystem.Collections.Generic;namespaceReverWords{classMainClass{publicstaticvoidMain(string[]args){Console.WriteLine(ReverseWords("HelloWorld"));Console.Read();}publicstaticstringReverseWords(stringarray){if(string.IsNullOrEmpty(array)){thrownewArgumentException("" 阅读全文
posted @ 2011-05-26 22:49 abstract未央 阅读(482) 评论(0) 推荐(0)

摘要:中软面试第二轮,被推到微软面试,这个题目:/* 输入:两个有序数组 * 输入:合并后的排序数组 */ 当时一片空白了。我写了一个,人家说效率低下,事后写的方法,以防忘记 // 将小的值加到result,并将该数组下标+1, // 如果相等,则将其任意一个加到result,两数组下标均+1 // 如果下标超出该数组长度,则退出循环 staticList<int>MergeArray(int[]a,int[]b){intidxa=0;intidxb=0;List<int>result=newList<int>();while(true){if(idxa>a 阅读全文
posted @ 2011-05-26 18:15 abstract未央 阅读(370) 评论(0) 推荐(0)

摘要:字符串反转的N种方法 数组反转。这的确是一道非常基础的算法题,然而也是一道很不平常的算法题(也许所有的算法深究下去都会很不平常)。因为我写着写着,就写出来8种方法……现在我们以字符串的反转为例,来介绍这几种方法并对它们的性能进行比较。使用Array.Reverse方法对于字符串反转,我们可以使用.NET类库自带的Array.Reverse方法public static string ReverseByArray(this string original){ char[] c = original.ToCharArray(); Array.Reverse(c); return new strin 阅读全文
posted @ 2011-05-25 22:49 abstract未央 阅读(746) 评论(0) 推荐(0)