Skip to content

Commit 0ef0f8e

Browse files
author
Partho Biswas
committed
no message
1 parent d986bad commit 0ef0f8e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
class Solution {
2+
func largestTimeFromDigits(_ A: [Int]) -> String {
3+
var permutations = [[Int]]()
4+
let sortedA = A.sorted(by: >)
5+
for i in 0..<sortedA.count {
6+
for j in 0..<sortedA.count {
7+
if j == i {
8+
continue
9+
}
10+
for k in 0..<sortedA.count {
11+
if k == i || k == j {
12+
continue
13+
}
14+
for l in 0..<sortedA.count {
15+
if l == i || l == j || l == k {
16+
continue
17+
}
18+
let permutation = [sortedA[i], sortedA[j], sortedA[k], sortedA[l]]
19+
permutations.append(permutation)
20+
}
21+
}
22+
}
23+
}
24+
25+
for permutation in permutations {
26+
let (hour, minuites) = ((permutation[0]*10) + permutation[1], (permutation[2]*10) + permutation[3])
27+
if hour < 24 && minuites < 60 {
28+
var (hourStr, minuitesStr) = (String(hour), String(minuites))
29+
if hour < 10 {
30+
hourStr = "0" + hourStr
31+
}
32+
if minuites < 10 {
33+
minuitesStr = "0" + minuitesStr
34+
}
35+
return hourStr + ":" + minuitesStr
36+
}
37+
}
38+
return ""
39+
}
40+
}

0 commit comments

Comments
 (0)