20241024 finished.

This commit is contained in:
2024-10-24 09:08:13 +08:00
parent 3102da99a8
commit bce8de1c85
266 changed files with 2321 additions and 2014 deletions

View File

@@ -3,14 +3,11 @@
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn maximum_odd_binary_number(s: String) -> String {
let nums: Vec<u32> = s.chars()
.map(|c| c.to_digit(10).unwrap())
.collect();
let nums: Vec<u32> = s.chars().map(|c| c.to_digit(10).unwrap()).collect();
let mut one_count = 0;
let mut zero_count = 0;
@@ -25,7 +22,7 @@ impl Solution {
let mut result: Vec<char> = Vec::with_capacity(nums.len());
for _ in 1..one_count {
for _ in 1..one_count {
result.push('1');
}
@@ -47,6 +44,9 @@ mod tests {
#[test]
fn test_2864() {
assert_eq!("001", Solution::maximum_odd_binary_number("010".to_owned()));
assert_eq!("1001", Solution::maximum_odd_binary_number("0101".to_owned()));
assert_eq!(
"1001",
Solution::maximum_odd_binary_number("0101".to_owned())
);
}
}