原题题目
代码实现(首刷大部分看解小部分自解)
class Solution {
public:int minTaps(int n, vector<int>& ranges) {
vector<int> dp(n+1,INT_MAX);int l,r,pre;for(int i=0;i<=n;++i){
if(!ranges[i]) continue;l = max(0,i-ranges[i]);r = min(n,i+ranges[i]);pre = (l<=0 ? 0: dp[l]);if(pre == INT_MAX) continue;for(int temp = l;temp<=r;temp++)dp[temp] = min(dp[temp],pre+1);}return dp[n]==INT_MAX ? -1:dp[n];}
};