Skip to content

Commit a6ef601

Browse files
authored
Merge pull request #279 from hellomrsun/master
Add Largest Time for Given Digits C#
2 parents f2fffc2 + 9672569 commit a6ef601

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
https://leetcode.com
44

5+
## September LeetCoding Challenge
6+
Click [here](https://leetcode.com/explore/challenge/card/september-leetcoding-challenge) for problem descriptions.
7+
8+
Solutions in various programming languages are provided. Enjoy it.
9+
10+
1. [Largest Time for Given Digits](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/01-Largest-Time-for-Given-Digits)
11+
512
## August LeetCoding Challenge
613
Click [here](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/) for problem descriptions.
714

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
public class Solution {
2+
public string LargestTimeFromDigits(int[] A) {
3+
var l = new Queue<string>();
4+
l.Enqueue("");
5+
6+
for(int n=0; n<A.Length; n++){
7+
for(int size = l.Count; size>0; size--){
8+
var s = l.Dequeue();
9+
for(int i=0; i<=s.Length; i++){
10+
l.Enqueue(s.Substring(0,i) + A[n] + s.Substring(i));
11+
}
12+
}
13+
}
14+
15+
var largest = "";
16+
foreach(var s in l){
17+
var t = s.Substring(0, 2) + ":" + s.Substring(2);
18+
if(t[3] < '6' && t.CompareTo("24:00") <0 && t.CompareTo(largest)>0){
19+
largest = t;
20+
}
21+
}
22+
23+
return largest;
24+
}
25+
}

0 commit comments

Comments
 (0)