一道面试题,觉得有更优化解# JobHunting - 待字闺中
r*o
1 楼
Given a target number and a set of numbers, using only addition,
multiplication, division and subtraction and the set of numbers get as near
to the target as possible
楼主想到的一个解法是用5向递归。具体代码怎么factor才简洁不知道~
function : void getNearest(numbers,target,tempTarget,path,re,visited)
base case :
tempRe = target;
getNearest( .. ,target/current, ...)
getNearest( .. ,target*current, ...)
getNearest( .. ,target+current, ...)
getNearest( .. ,target-current, ...)
getNearest( .. ,target, ...)
呵呵,欢迎大家讨论更简洁的算法!
multiplication, division and subtraction and the set of numbers get as near
to the target as possible
楼主想到的一个解法是用5向递归。具体代码怎么factor才简洁不知道~
function : void getNearest(numbers,target,tempTarget,path,re,visited)
base case :
tempRe = target;
getNearest( .. ,target/current, ...)
getNearest( .. ,target*current, ...)
getNearest( .. ,target+current, ...)
getNearest( .. ,target-current, ...)
getNearest( .. ,target, ...)
呵呵,欢迎大家讨论更简洁的算法!