Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6b4b3ab

Browse files
author
guangsheng.li01
committed
Solved 0949
1 parent 34d0d7a commit 6b4b3ab

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* [0646] maximum-length-of-pair-chain
3+
*/
4+
5+
pub struct Solution {}
6+
7+
// solution impl starts here
8+
9+
impl Solution {
10+
fn add(a: i32, b: i32) -> i32 {
11+
a + b
12+
}
13+
}
14+
15+
// solution impl ends here
16+
17+
// solution tests starts here
18+
19+
#[cfg(test)]
20+
mod tests {
21+
use super::*;
22+
23+
#[test]
24+
fn test_case0() {
25+
assert_eq!(5, Solution::add(2, 3));
26+
}
27+
}
28+
29+
// solution tests ends here
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* [0949] largest-time-for-given-digits
3+
*/
4+
5+
pub struct Solution {}
6+
7+
// solution impl starts here
8+
9+
impl Solution {
10+
pub fn largest_time_from_digits(a: Vec<i32>) -> String {
11+
let mut a = a;
12+
a.sort();
13+
a.reverse();
14+
for i in 0..4 {
15+
if a[i] > 2 {
16+
continue;
17+
}
18+
19+
for j in 0..4 {
20+
if j == i || (a[i] == 2 && a[j] > 3) {
21+
continue;
22+
}
23+
24+
for k in 0..4 {
25+
if k == i || k == j || a[k] > 5 {
26+
continue;
27+
}
28+
29+
return format!("{}{}:{}{}", a[i], a[j], a[k], a[6 - i - j - k]);
30+
}
31+
}
32+
}
33+
"".to_string()
34+
}
35+
}
36+
37+
// solution impl ends here
38+
39+
// solution tests starts here
40+
41+
#[cfg(test)]
42+
mod tests {
43+
use super::*;
44+
45+
#[test]
46+
fn test_case0() {
47+
assert_eq!(
48+
Solution::largest_time_from_digits(vec![1, 2, 3, 4]),
49+
"23:41"
50+
);
51+
assert_eq!(Solution::largest_time_from_digits(vec![5, 5, 5, 5]), "");
52+
}
53+
}
54+
55+
// solution tests ends here

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ mod a0867_transpose_matrix;
2727
mod a0929_unique_email_addresses;
2828
mod a0931_minimum_falling_path_sum;
2929
mod a0937_reorder_data_in_log_files;
30+
mod a0949_largest_time_for_given_digits;
3031
mod a0973_k_closest_points_to_origin;
3132
mod a1021_remove_outermost_parentheses;
3233
mod a1047_remove_all_adjacent_duplicates_in_string;

0 commit comments

Comments
 (0)