Skip to content

Commit 7cf0b5d

Browse files
committed
228
1 parent c9942d7 commit 7cf0b5d

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

leetcode/2188. Minimum Time to Finish the Race/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public:
7272
int N = A.size(), len = 0;
7373
vector<long> best(numLaps, LONG_MAX), dp(numLaps + 1, INT_MAX);
7474
for (int i = 0; i < N; ++i) {
75-
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
75+
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
7676
for (int j = 0; j < numLaps; ++j) {
7777
sum += f * p;
7878
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

leetcode/228. Summary Ranges/README.md

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,20 @@
3333
[8,9] --&gt; "8-&gt;9"
3434
</pre>
3535

36-
<p><strong>Example 3:</strong></p>
37-
38-
<pre><strong>Input:</strong> nums = []
39-
<strong>Output:</strong> []
40-
</pre>
41-
42-
<p><strong>Example 4:</strong></p>
43-
44-
<pre><strong>Input:</strong> nums = [-1]
45-
<strong>Output:</strong> ["-1"]
46-
</pre>
47-
48-
<p><strong>Example 5:</strong></p>
49-
50-
<pre><strong>Input:</strong> nums = [0]
51-
<strong>Output:</strong> ["0"]
52-
</pre>
53-
5436
<p>&nbsp;</p>
5537
<p><strong>Constraints:</strong></p>
5638

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

6346

47+
**Companies**:
48+
[Yandex](https://leetcode.com/company/yandex), [Facebook](https://leetcode.com/company/facebook), [Google](https://leetcode.com/company/google)
49+
6450
**Related Topics**:
6551
[Array](https://leetcode.com/tag/array/)
6652

@@ -89,3 +75,25 @@ public:
8975
}
9076
};
9177
```
78+
79+
Or
80+
81+
```cpp
82+
// OJ: https://leetcode.com/problems/summary-ranges/
83+
// Author: github.com/lzl124631x
84+
// Time: O(N)
85+
// Space: O(N)
86+
class Solution {
87+
public:
88+
vector<string> summaryRanges(vector<int>& A) {
89+
vector<string> ans;
90+
int N = A.size();
91+
for (int i = 0; i < N; ++i) {
92+
int start = A[i];
93+
while (i + 1 < N && A[i + 1] == A[i] + 1) ++i;
94+
ans.push_back(to_string(start) + (A[i] == start ? "" : ("->" + to_string(A[i]))));
95+
}
96+
return ans;
97+
}
98+
};
99+
```

0 commit comments

Comments
 (0)