Skip to content

Commit

Permalink
Add Largest Time for Given Digits C#
Browse files Browse the repository at this point in the history
  • Loading branch information
hellomrsun committed Sep 1, 2020
1 parent f2fffc2 commit 9672569
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

https://leetcode.com

## September LeetCoding Challenge
Click [here](https://leetcode.com/explore/challenge/card/september-leetcoding-challenge) for problem descriptions.

Solutions in various programming languages are provided. Enjoy it.

1. [Largest Time for Given Digits](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/01-Largest-Time-for-Given-Digits)

## August LeetCoding Challenge
Click [here](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/) for problem descriptions.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
public class Solution {
public string LargestTimeFromDigits(int[] A) {
var l = new Queue<string>();
l.Enqueue("");

for(int n=0; n<A.Length; n++){
for(int size = l.Count; size>0; size--){
var s = l.Dequeue();
for(int i=0; i<=s.Length; i++){
l.Enqueue(s.Substring(0,i) + A[n] + s.Substring(i));
}
}
}

var largest = "";
foreach(var s in l){
var t = s.Substring(0, 2) + ":" + s.Substring(2);
if(t[3] < '6' && t.CompareTo("24:00") <0 && t.CompareTo(largest)>0){
largest = t;
}
}

return largest;
}
}

0 comments on commit 9672569

Please sign in to comment.