摘要: Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two nu... 阅读全文
posted @ 2014-07-23 06:56 Ligeance 阅读(190) 评论(0) 推荐(0) 编辑
摘要: Excel中的行列数用A~Z 26个字母表示,A, B, C, D, …, Z, AA, AB, …, AZ, BA, BB, … 分别表示10进制数1, 2, 3, 4, …, 26, 27, 28, …, 52, 53, 54…。请实现2个函数decToExcel和excelToDec,将10进制数转换为Excel数,以及将Excel数转换为10进制数。有个小BUG,当26的时候显示为@A……不知道为啥会这样。已修复@A的BUG。using System;using System.Collections;using System.Collections.Generic;using Syst 阅读全文
posted @ 2014-02-25 15:49 Ligeance 阅读(191) 评论(0) 推荐(0) 编辑
摘要: 例如15则返回F,20则返回14.using System;using System.Collections;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication20{ class Program { static void Main(string[] args) { int n = -18; Console.Write(ConvertIntToHex(n)); ... 阅读全文
posted @ 2014-02-18 16:15 Ligeance 阅读(993) 评论(0) 推荐(0) 编辑
摘要: 有一个长度为n的整型数组arr,从中选出3个数a,b,c,使得a+b+c=0,找出所有满足条件的三元组(a,b,c)。重复的三元组只算一次。样例:数组[2, 1, -3, -3, 0, -1],满足条件的三元组有2个:(2, 1, -3)和(1, 0, -1)。提示:本题存在空间复杂度O(1)的算法(不使用任何辅助空间),没必要利用set等数据结构消除重复的三元组。不知道咋实现LIST的三元数组啊……找了找,没找到。只能用蠢办法了。using System;using System.Collections.Generic;using System.Linq;using System.Text; 阅读全文
posted @ 2014-02-11 15:58 Ligeance 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 给定一个非负整数a(不超过106),是否存在整数b,使得a和b的乘积全为1。如果存在,返回最小的乘积的位数。如果不存在,返回-1。样例:a=3,存在b=37,使得3*37=111,则函数应返回3(111的位数)。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication15{ class Program { static void Main(string[] args) { ... 阅读全文
posted @ 2014-02-10 14:37 Ligeance 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 如果字符串str3能够由str1和str2中的字符按顺序交替形成,那么称str3为str1和str2的交替字符串。例如str1="abc",str2="def",那么"adbecf", "abcdef", "abdecf", "abcdef", "adefbc"等等都为str1和str2的交替字符串。更形式化的,str3的生成算法如下:str3=""while str1不为空 or str2不为空: 把str1或str2的首字符加入到s 阅读全文
posted @ 2014-02-10 13:58 Ligeance 阅读(605) 评论(0) 推荐(0) 编辑
摘要: 有2个长度为n和m的有序的整型数组arr1和arr2,请将他们合并为一个n+m的有序数组。注意:数组arr1包含足够的空间存放下n+m个元素,请直接将结果合并到数组arr1中。提示:不要使用任何辅助数组,辅助空间。样例:n=3m=2arr1: [1,4,8,x,x]arr2: [-1,5]算法运行后arr1应该为[-1,1,4,5,8]using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication13{ class Program ... 阅读全文
posted @ 2014-02-05 16:48 Ligeance 阅读(262) 评论(0) 推荐(0) 编辑
摘要: 有一个长度为n的字符串str,有非常多的关键字query(长度不超过10),需要判断每个关键字是否是str的子串。注意:query是动态的输入进行查询的,预先并不知道所有的query。请实现2个函数initWithString(str)和existSubString(query)。我们会首先调用一次initWithString(str),你可以在这个函数中做一些预处理操作。然后对于每一个query,函数existSubString(query)需要返回这个query是否为str的子串。感觉理解题目有问题,总之,先写下来练习吧。using System;using System.Collecti 阅读全文
posted @ 2014-02-05 15:32 Ligeance 阅读(195) 评论(0) 推荐(0) 编辑
摘要: 有n个左右端点都为整数的区间,判断每个区间是否有与其它某个区间相交(区间端点重合也算相交)。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication11{ class Program { static void Main(string[] args) { Interval a = new Interval(1, 4); Interval b = n... 阅读全文
posted @ 2014-02-05 14:35 Ligeance 阅读(470) 评论(0) 推荐(0) 编辑
摘要: using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication10{ class Program { static void Main(string[] args) { int[] intArr = { 8,2,5,9,4,1,3,7,-1}; MaxMin result = FindMaxAndMin(intArr, 0, intArr.Length... 阅读全文
posted @ 2014-02-04 16:10 Ligeance 阅读(1124) 评论(0) 推荐(0) 编辑