-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #994 from 0xff-dev/949
Add solution and test-cases for problem 949
- Loading branch information
Showing
3 changed files
with
53 additions
and
23 deletions.
There are no files selected for viewing
27 changes: 13 additions & 14 deletions
27
leetcode/901-1000/0949.Largest-Time-for-Given-Digits/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 34 additions & 2 deletions
36
leetcode/901-1000/0949.Largest-Time-for-Given-Digits/Solution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,37 @@ | ||
package Solution | ||
|
||
func Solution(x bool) bool { | ||
return x | ||
import "fmt" | ||
|
||
func Solution(arr []int) string { | ||
in := make(map[int]int) | ||
for _, n := range arr { | ||
in[n]++ | ||
} | ||
var a, b, c, d int | ||
for i := 23; i >= 0; i-- { | ||
a, b = i/10, i%10 | ||
if a == b { | ||
if in[a] < 2 { | ||
continue | ||
} | ||
} else if in[a] < 1 || in[b] < 1 { | ||
continue | ||
} | ||
in[a]-- | ||
in[b]-- | ||
|
||
for j := 59; j >= 0; j-- { | ||
c, d = j/10, j%10 | ||
if c == d { | ||
if in[c] >= 2 { | ||
return fmt.Sprintf("%d%d:%d%d", a, b, c, d) | ||
} | ||
} else if in[c] > 0 && in[d] > 0 { | ||
return fmt.Sprintf("%d%d:%d%d", a, b, c, d) | ||
} | ||
} | ||
in[a]++ | ||
in[b]++ | ||
} | ||
return "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters