FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/C++/next-closest-time.cpp at master · tehsints/LeetCode-Solutions · GitHub
tehsints
LeetCode-Solutions
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode-Solutions
/
C++
/
next-closest-time.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
23 lines (22 loc) · 727 Bytes
Breadcrumbs
LeetCode-Solutions
/
C++
/
next-closest-time.cpp
Copy path
File metadata and controls
23 lines (22 loc) · 727 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//
Time: O(1)
//
Space: O(1)
class
Solution
{
public:
string
nextClosestTime
(string time) {
static
const
vector<
int
> mins = {
600
,
60
,
10
,
1
};
auto
npos = time.
find
(
'
:
'
);
auto
curr =
stoi
(time.
substr
(
0
, npos)) *
60
+
stoi
(time.
substr
(npos +
1
));
string result =
"
0000
"
;
for
(
int
i =
1
, d =
0
; i <=
1440
&& d <
4
; ++i) {
int
m = (curr + i) %
1440
;
for
(d =
0
; d <
4
; ++d) {
result[d] =
'
0
'
+ m / mins[d]; m %= mins[d];
if
(time.
find
(result[d]) == string::npos) {
break
;
}
}
}
return
result.
substr
(
0
,
2
) +
'
:
'
+ result.
substr
(
2
,
2
);
}
};
Back
|
FazBrowse Home
|
New Git URL