Skip to content

Add Largest Time for Given Digits C# #279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}