Skip to content

Commit c2bd958

Browse files
committed
panic if string is empty -- manacher
1 parent 2b1100e commit c2bd958

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/strings/manacher.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@
1717
/// assert_eq!(manacher(&"baaba".chars().collect::<Vec<_>>()), vec![0, 1, 1, 0, 2, 3, 2, 4, 4]);
1818
/// ```
1919
///
20+
/// # Panics
21+
/// ```panic
22+
/// use programming_team_code_rust::strings::manacher::manacher;
23+
/// manacher(&"".chars().collect::<Vec<_>>());
24+
/// ```
25+
///
2026
/// # Complexity (n = s.len())
2127
/// - Time: O(n)
2228
/// - Space: O(n)
2329
pub fn manacher<T: std::cmp::PartialEq>(s: &[T]) -> Vec<usize> {
24-
if s.is_empty() {
25-
return vec![];
26-
}
2730
let n = s.len();
2831
let mut p = 0;
2932
let mut man = vec![0; 2 * n - 1];

0 commit comments

Comments
 (0)