JS实现动态规划
/**
*
* @param prices int整型一维数组
* @return int整型
*/
function maxProfit( prices ) {
// write code here
var minValue=prices[0];
var profile=0;
for(var i=0;i<prices.length;i++){
minValue=Math.min(minValue,prices[i]);
profile=Math.max(profile,prices[i]-minValue);
}
return profile;
}
module.exports = {
maxProfit : maxProfit
}; 
京公网安备 11010502036488号