feat: 3280_convert_date_to_binary

This commit is contained in:
SquidSpirit 2025-08-20 22:32:32 +08:00
parent 18d9c661e8
commit 758200be5c
3 changed files with 25 additions and 0 deletions

7
3280_convert_date_to_binary/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "convert_date_to_binary"
version = "0.1.0"

View File

@ -0,0 +1,6 @@
[package]
name = "convert_date_to_binary"
version = "0.1.0"
edition = "2024"
[dependencies]

View File

@ -0,0 +1,12 @@
pub struct Solution;
impl Solution {
pub fn convert_date_to_binary(date: String) -> String {
let [y, m, d]: [i32; 3] = date.split('-')
.map(|num_str| num_str.parse().unwrap())
.collect::<Vec<i32>>()
.try_into()
.unwrap();
format!("{:b}-{:b}-{:b}", y, m, d)
}
}