标签:|| mat map rev number pre filter code ===
function fn(src, dst, k) { //对n个城市m个航班做飞行说明 let fights = [ [0,1,100], [1,2,100], [0,2,500] ]; //计算最便宜的路线 let cheap = (src, dst, k) => { // 找到dst的前一站 let prev = fights.filter(i=>i[1]==dst); let min = Math.min.apply(null, prev.map(i =>{ //从des向前找,找到了其实的城市 if (i[0]===src&&k>-1) { return i[2] } else if(k===0&&item[0]!=src){ return Number.MAX_SAFE_INTEGER; } else { return i[2] + cheap(src, item[0],k-1) } })) return min; } return cheap(src, dst, k) || -1; }
标签:|| mat map rev number pre filter code ===
原文地址:https://www.cnblogs.com/Ingots/p/11504134.html