File tree Expand file tree Collapse file tree 4 files changed +54
-1
lines changed
problem_2103_rings_and_rods
problem_2864_maximum_odd_binary_number Expand file tree Collapse file tree 4 files changed +54
-1
lines changed Original file line number Diff line number Diff line change 14
14
clippy:: cast_sign_loss,
15
15
clippy:: missing_panics_doc,
16
16
clippy:: must_use_candidate,
17
+ clippy:: naive_bytecount,
17
18
reason = "unnecessary"
18
19
) ]
19
20
@@ -1994,6 +1995,7 @@ pub mod problem_2849_determine_if_a_cell_is_reachable_at_a_given_time;
1994
1995
pub mod problem_2855_minimum_right_shifts_to_sort_the_array;
1995
1996
pub mod problem_2856_minimum_array_length_after_pair_removals;
1996
1997
pub mod problem_2859_sum_of_values_at_indices_with_k_set_bits;
1998
+ pub mod problem_2864_maximum_odd_binary_number;
1997
1999
1998
2000
#[ cfg( test) ]
1999
2001
mod test_utilities;
Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ pub struct Solution;
3
3
// ------------------------------------------------------ snip ------------------------------------------------------ //
4
4
5
5
impl Solution {
6
- #[ expect( clippy:: naive_bytecount, reason = "optimal" ) ]
7
6
pub fn count_points ( rings : String ) -> i32 {
8
7
let mut iter_2 = rings. bytes ( ) ;
9
8
Original file line number Diff line number Diff line change
1
+ pub struct Solution ;
2
+
3
+ // ------------------------------------------------------ snip ------------------------------------------------------ //
4
+
5
+ impl Solution {
6
+ pub fn maximum_odd_binary_number ( s : String ) -> String {
7
+ let mut s = s. into_bytes ( ) ;
8
+ let ones = s. iter ( ) . filter ( |& & c| c == b'1' ) . count ( ) ;
9
+ let ( left, right) = s. split_at_mut ( ones - 1 ) ;
10
+ let ( last, rest) = right. split_last_mut ( ) . unwrap ( ) ;
11
+
12
+ left. fill ( b'1' ) ;
13
+ rest. fill ( b'0' ) ;
14
+ * last = b'1' ;
15
+
16
+ String :: from_utf8 ( s) . unwrap ( )
17
+ }
18
+ }
19
+
20
+ // ------------------------------------------------------ snip ------------------------------------------------------ //
21
+
22
+ impl super :: Solution for Solution {
23
+ fn maximum_odd_binary_number ( s : String ) -> String {
24
+ Self :: maximum_odd_binary_number ( s)
25
+ }
26
+ }
27
+
28
+ #[ cfg( test) ]
29
+ mod tests {
30
+ #[ test]
31
+ fn test_solution ( ) {
32
+ super :: super :: tests:: run :: < super :: Solution > ( ) ;
33
+ }
34
+ }
Original file line number Diff line number Diff line change
1
+ pub mod greedy;
2
+
3
+ pub trait Solution {
4
+ fn maximum_odd_binary_number ( s : String ) -> String ;
5
+ }
6
+
7
+ #[ cfg( test) ]
8
+ mod tests {
9
+ use super :: Solution ;
10
+
11
+ pub fn run < S : Solution > ( ) {
12
+ let test_cases = [ ( "010" , "001" ) , ( "0101" , "1001" ) ] ;
13
+
14
+ for ( s, expected) in test_cases {
15
+ assert_eq ! ( S :: maximum_odd_binary_number( s. to_string( ) ) , expected) ;
16
+ }
17
+ }
18
+ }
You can’t perform that action at this time.
0 commit comments