标签:i++ https 情况 图片 src mamicode for http ==
数学方法,一共k+1种情况:使用shorter0次到k次。一个循环把i*shorter+(k-i)*longer,0<=i<=k算一遍即可。
class Solution { public: vector<int> divingBoard(int shorter, int longer, int k) { vector<int> board; if(k==0) return board; int temp; for(int i=0;i<=k;i++){ temp = (k-i)*shorter+i*longer; if(i==0) board.push_back(temp); else if(temp>board.back()) board.push_back(temp); } return board; } };
注意考虑特殊情况:
标签:i++ https 情况 图片 src mamicode for http ==
原文地址:https://www.cnblogs.com/BoysCryToo/p/13265335.html