Skip to content

Commit bb11b93

Browse files
committed
cpp
1 parent e9831c2 commit bb11b93

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
string largestTimeFromDigits(vector<int>& A) {
4+
string ans="";
5+
6+
for(int i=0;i<A.size();i++){
7+
ans+=to_string(A[i]);
8+
}
9+
sort(ans.begin(),ans.end());
10+
string sol="";
11+
do{
12+
string first=ans.substr(0,2);
13+
string second=ans.substr(2,2);
14+
int first1=stoi(first);
15+
int second1=stoi(second);
16+
if(first1>=0 && first1<=23 && second1>=0 && second1<=59){
17+
sol=max(sol,first + ":" + second);
18+
}
19+
}
20+
while(next_permutation(ans.begin(),ans.end()));
21+
return sol;
22+
}
23+
};

0 commit comments

Comments
 (0)