-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added max repeating substring solution.
- Loading branch information
Showing
3 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
pub fn max_repeating(sequence: String, word: String) -> i32 { | ||
let mut sub_str = "".to_string(); | ||
while sequence.contains(&sub_str) { | ||
sub_str.push_str(&word) | ||
} | ||
let result = (sub_str.len() - word.len()) / word.len(); | ||
result as i32 | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn find_max_repeating() { | ||
let actual = max_repeating("ababc".to_string(), "ab".to_string()); | ||
assert_eq!(2, actual); | ||
|
||
let actual = max_repeating("ababc".to_string(), "abcd".to_string()); | ||
assert_eq!(0, actual) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,4 @@ mod intersection_two; | |
mod x_kind; | ||
mod remove_duplicates; | ||
mod sort_people; | ||
mod max_repeating_substr; |