摘要: 题目:一个整型数组里除了两个数字之外,其他的数字都出现了两次。请写程序找出这两个只出现一次的数字。要求时间复杂度是O(n),空间复杂度是O(1)。// Find two numbers which only appear once in an array// Input: data - an array contains two number appearing exactly once,// while others appearing exactly twice// Output: num1 - the first number appearing once in data// num2 阅读全文
posted @ 2014-01-08 16:58 purplesun 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 题目:在数组中,数字减去它右边的数字得到一个数对之差。求所有数对之差的最大值。例如在数组{2, 4, 1, 16, 7, 5, 11, 9}中,数对之差的最大值是11,是16减去5的结果。static int MaxDiff(int[] arr){if(arr.Length max){max = arr[i - 1];}int currentDiff = max - arr[i];if (currentDiff > maxDiff){maxDiff = currentDiff;}}return maxDiff;} 阅读全文
posted @ 2014-01-08 15:35 purplesun 阅读(221) 评论(0) 推荐(0) 编辑