
Algorithms
文章平均质量分 73
luozhongrong_06
这个作者很懒,什么都没留下…
展开
-
求数组中连续最大和值,时间复杂度为O(n)
自己写的,感觉对了,贴出来show。static int[] GetSequementSumMax(int[] arr) { int[] arrOld = new int[2]; int[] arrNew = new int[2]; int sumMaxOld = 0; int sumMaxN原创 2011-06-19 21:59:00 · 674 阅读 · 0 评论 -
Find the nearest common ancestor of any two nodes in a binary search tree
自己写的,贴出来show一下,接受拍砖.1. creat binary tree static void CreateBinaryTree(int i, int? isOut = null){ if (binaryRootNode == null){ BinaryNode node = new BinaryNode();原创 2011-06-20 15:16:00 · 540 阅读 · 0 评论 -
找出和值等于指定值的元素,如有序数组{1,2,6,23,43,64},求和等于25的两个和数则将是元素2和23,时间复杂度是0(n)。
这道题有两个关键点,第一是数组有序,第二是时间复杂度是0(n)。思路:可以从数组最后一个往前循环,那么最小的肯定在最前面。同理从前面往后面循环也是一样的,注意退出的关键点即可。改良代码:static string GetAddendsNew(int[] arrAddends, int sum) { for (int i = 0, j = arrAdd原创 2011-06-28 17:21:00 · 1235 阅读 · 0 评论