我需要一种算法,以确定是否一个数组包含两个要素总和到一个给定的整数。
I need an algorithm to determine if an array contains two elements that sum to a given integer.
数组排序。
该算法应该是递归并为O(N)。
The algorithm should be recursive and runs in O(n).
递归步骤应基于总和,这意味着该方法进入的总和,并返回真或假根据最终结果(如果两个元件发现 - 返回true,否则 - 返回false)
The recursive step should be based on the sum, meaning the method passes the sum and return true or false depending on the end result (if two elements are found - return true, else - return false)
仅线性数据结构都可以使用。
Only linear data structures can be used.
任何想法是AP preciated ..
Any ideas are appreciated..
推荐答案您可以将任何迭代算法为递归其用(例如)的尾递归。我会更广阔,如果不是功课。我想你会明白它的其他职位。
You can convert any iterative algorithm into a recursive one by using (for instance) tail recursion. I'd be more expansive, if it weren't homework. I think you'll understand it from the other post.
更多推荐
递归算法找到两个整数求和给定的整数数组
发布评论