思路:
贪心+构造。
实现:
1 class Solution 2 { 3 public: 4 long long numberOfWeeks(vector<int>& milestones) 5 { 6 int n = milestones.size(); 7 long long sum = 0, maxn = 0; 8 for (int i = 0; i < n; i++) 9 { 10 maxn = max(maxn, (long long)milestones[i]); 11 sum += milestones[i]; 12 } 13 long long res = sum - maxn; 14 if (maxn <= res + 1) return sum; 15 return 2 * res + 1; 16 } 17 };