Skip to content

Commit a111908

Browse files
committed
feat: resolved
1 parent 57c879a commit a111908

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

Cargo.lock

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ members = [
3131
"find_and_replace_pattern",
3232
"to_lower_case",
3333
"evaluate_reverse_polish_notation",
34+
"partitioning_into_minimum_number_of_deci_binary_numbers",
3435
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "partitioning_into_minimum_number_of_deci_binary_numbers"
3+
version = "0.1.0"
4+
authors = ["Ryan Li <conbas2019@gmail.com>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
pub struct Solution {}
2+
3+
impl Solution {
4+
pub fn min_partitions(n: String) -> i32 {
5+
n.chars().max().unwrap() as i32 - '0' as i32
6+
}
7+
}
8+
9+
#[cfg(test)]
10+
mod tests {
11+
use super::*;
12+
13+
fn it_works(n: &str, expected: i32) {
14+
assert_eq!(Solution::min_partitions(n.to_string()), expected);
15+
}
16+
17+
#[test]
18+
fn example_1() {
19+
it_works("32", 3);
20+
}
21+
22+
#[test]
23+
fn example_2() {
24+
it_works("82734", 8);
25+
}
26+
27+
#[test]
28+
fn example_3() {
29+
it_works("27346209830709182346", 9);
30+
}
31+
}

0 commit comments

Comments
 (0)