Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9a82099

Browse files
committed
fix: update cpp solution in lc/lcof2 problem and close doocs#588
lc&lcof2 problem: Minimum Time Difference
1 parent 1206b0b commit 9a82099

File tree

3 files changed

+33
-44
lines changed

3 files changed

+33
-44
lines changed

‎lcof2/剑指 Offer II 035. 最小时间差/README.md‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
<p><meta charset="UTF-8" />注意:本题与主站 539&nbsp;题相同:&nbsp;<a href="https://leetcode-cn.com/problems/minimum-time-difference/">https://leetcode-cn.com/problems/minimum-time-difference/</a></p>
3737

38-
3938
## 解法
4039

4140
<!-- 这里可写通用的实现逻辑 -->
@@ -95,24 +94,21 @@ class Solution {
9594

9695
```cpp
9796
class Solution {
98-
public int findMinDifference(List<String> timePoints) {
99-
if (timePoints.size() > 24 * 60) {
97+
public:
98+
int findMinDifference(vector<string> &timePoints) {
99+
if (timePoints.size() > 24 * 60)
100100
return 0;
101-
}
102-
List<Integer> mins = new ArrayList<>();
103-
for (String t : timePoints) {
104-
String[] time = t.split(":");
105-
mins.add(Integer.parseInt(time[0]) * 60 + Integer.parseInt(time[1]));
106-
}
107-
Collections.sort(mins);
108-
mins.add(mins.get(0) + 24 * 60);
101+
vector<int> mins;
102+
for (auto t : timePoints)
103+
mins.push_back(stoi(t.substr(0, 2)) * 60 + stoi(t.substr(3)));
104+
sort(mins.begin(), mins.end());
105+
mins.push_back(mins[0] + 24 * 60);
109106
int res = 24 * 60;
110-
for (int i = 1; i < mins.size(); ++i) {
111-
res = Math.min(res, mins.get(i) - mins.get(i - 1));
112-
}
107+
for (int i = 1; i < mins.size(); ++i)
108+
res = min(res, mins[i] - mins[i - 1]);
113109
return res;
114110
}
115-
}
111+
};
116112
```
117113
118114
### **Go**

‎solution/0500-0599/0539.Minimum Time Difference/README.md‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,21 @@ class Solution {
9292

9393
```cpp
9494
class Solution {
95-
public int findMinDifference(List<String> timePoints) {
96-
if (timePoints.size() > 24 * 60) {
95+
public:
96+
int findMinDifference(vector<string> &timePoints) {
97+
if (timePoints.size() > 24 * 60)
9798
return 0;
98-
}
99-
List<Integer> mins = new ArrayList<>();
100-
for (String t : timePoints) {
101-
String[] time = t.split(":");
102-
mins.add(Integer.parseInt(time[0]) * 60 + Integer.parseInt(time[1]));
103-
}
104-
Collections.sort(mins);
105-
mins.add(mins.get(0) + 24 * 60);
99+
vector<int> mins;
100+
for (auto t : timePoints)
101+
mins.push_back(stoi(t.substr(0, 2)) * 60 + stoi(t.substr(3)));
102+
sort(mins.begin(), mins.end());
103+
mins.push_back(mins[0] + 24 * 60);
106104
int res = 24 * 60;
107-
for (int i = 1; i < mins.size(); ++i) {
108-
res = Math.min(res, mins.get(i) - mins.get(i - 1));
109-
}
105+
for (int i = 1; i < mins.size(); ++i)
106+
res = min(res, mins[i] - mins[i - 1]);
110107
return res;
111108
}
112-
}
109+
};
113110
```
114111
115112
### **Go**

‎solution/0500-0599/0539.Minimum Time Difference/README_EN.md‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ Given a list of 24-hour clock time points in <strong>&quot;HH:MM&quot;</strong>
2929
3. Push the time `mins[0] + 24 * 60` to deal with min and max diff.
3030
4. For each value in `mins[1:]`, calculate the min diff `mins[i] - mins[i - 1]`.
3131

32-
3332
<!-- tabs:start -->
3433

3534
### **Python3**
@@ -75,24 +74,21 @@ class Solution {
7574

7675
```cpp
7776
class Solution {
78-
public int findMinDifference(List<String> timePoints) {
79-
if (timePoints.size() > 24 * 60) {
77+
public:
78+
int findMinDifference(vector<string> &timePoints) {
79+
if (timePoints.size() > 24 * 60)
8080
return 0;
81-
}
82-
List<Integer> mins = new ArrayList<>();
83-
for (String t : timePoints) {
84-
String[] time = t.split(":");
85-
mins.add(Integer.parseInt(time[0]) * 60 + Integer.parseInt(time[1]));
86-
}
87-
Collections.sort(mins);
88-
mins.add(mins.get(0) + 24 * 60);
81+
vector<int> mins;
82+
for (auto t : timePoints)
83+
mins.push_back(stoi(t.substr(0, 2)) * 60 + stoi(t.substr(3)));
84+
sort(mins.begin(), mins.end());
85+
mins.push_back(mins[0] + 24 * 60);
8986
int res = 24 * 60;
90-
for (int i = 1; i < mins.size(); ++i) {
91-
res = Math.min(res, mins.get(i) - mins.get(i - 1));
92-
}
87+
for (int i = 1; i < mins.size(); ++i)
88+
res = min(res, mins[i] - mins[i - 1]);
9389
return res;
9490
}
95-
}
91+
};
9692
```
9793
9894
### **Go**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /