Skip to content

Commit

Permalink
228
Browse files Browse the repository at this point in the history
  • Loading branch information
lzl124631x committed Feb 28, 2022
1 parent c9942d7 commit 7cf0b5d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion leetcode/2188. Minimum Time to Finish the Race/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public:
int N = A.size(), len = 0;
vector<long> best(numLaps, LONG_MAX), dp(numLaps + 1, INT_MAX);
for (int i = 0; i < N; ++i) {
long f = A[i][0], r = A[i][1], sum = change, p = 1; // We assume we also need `change` time to use the first tire so that we don't need to care the first tire as a special case
long f = A[i][0], r = A[i][1], sum = change, p = 1; // We assume we also need `change` time to use the first tire so that we don't need to treat the first tire as a special case
for (int j = 0; j < numLaps; ++j) {
sum += f * p;
if (f * p >= f + change) break; // If using the same tire takes no less time than changing the tire, stop further using the current tire
Expand Down
44 changes: 26 additions & 18 deletions leetcode/228. Summary Ranges/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,20 @@
[8,9] --&gt; "8-&gt;9"
</pre>

<p><strong>Example 3:</strong></p>

<pre><strong>Input:</strong> nums = []
<strong>Output:</strong> []
</pre>

<p><strong>Example 4:</strong></p>

<pre><strong>Input:</strong> nums = [-1]
<strong>Output:</strong> ["-1"]
</pre>

<p><strong>Example 5:</strong></p>

<pre><strong>Input:</strong> nums = [0]
<strong>Output:</strong> ["0"]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>0 &lt;= nums.length &lt;= 20</code></li>
<li><code>-2<sup>31</sup> &lt;= nums[i] &lt;= 2<sup>31</sup> - 1</code></li>
<li>All the values of <code>nums</code> are <strong>unique</strong>.</li>
<li><code>nums</code> is sorted in ascending order.</li>
</ul>


**Companies**:
[Yandex](https://leetcode.com/company/yandex), [Facebook](https://leetcode.com/company/facebook), [Google](https://leetcode.com/company/google)

**Related Topics**:
[Array](https://leetcode.com/tag/array/)

Expand Down Expand Up @@ -89,3 +75,25 @@ public:
}
};
```
Or
```cpp
// OJ: https://leetcode.com/problems/summary-ranges/
// Author: github.com/lzl124631x
// Time: O(N)
// Space: O(N)
class Solution {
public:
vector<string> summaryRanges(vector<int>& A) {
vector<string> ans;
int N = A.size();
for (int i = 0; i < N; ++i) {
int start = A[i];
while (i + 1 < N && A[i + 1] == A[i] + 1) ++i;
ans.push_back(to_string(start) + (A[i] == start ? "" : ("->" + to_string(A[i]))));
}
return ans;
}
};
```

0 comments on commit 7cf0b5d

Please sign in to comment.