intfindPoisonedDuration(vector<int>& timeSeries,int duration){int time =0;int start = timeSeries[0], end = start + duration -1;// [start, end]for(int i =1; i < timeSeries.size();++i){if(timeSeries[i]<= end){
end = timeSeries[i]+ duration -1;}else{
time += end - start +1;
start = timeSeries[i];
end = start + duration -1;}}
time += end - start +1;return time;}intfindPoisonedDuration(vector<int>& timeSeries,int duration){int time =0;for(int i =1; i < timeSeries.size();++i){int interval = timeSeries[i]- timeSeries[i-1];if(interval >= duration) time += duration;else time += interval;}return time + duration;}
// tips:当发现一个模拟策略复杂度太高,大多数情况下都是在模拟中找规律来进行优化
string convert(string s,int numRows){if(s.size()<= numRows || numRows ==1)return s;
string ret;int interval =2* numRows -2;// 公差间隔for(int i =0; i < s.size(); i += interval) ret += s[i];for(int i =1; i < numRows -1;++i){for(int left = i, right = interval - left; left < s.size()|| right < s.size(); left += interval, right += interval){if(left < s.size()) ret += s[left];if(right < s.size()) ret += s[right];}}for(int i = numRows -1; i < s.size(); i += interval) ret += s[i];return ret;}