20250304 finished.
This commit is contained in:
parent
4b241b0a42
commit
16c61d436c
|
@ -516,3 +516,5 @@ mod p131_palindrome_partitioning;
|
||||||
mod p132_palindrome_partitioning_ii;
|
mod p132_palindrome_partitioning_ii;
|
||||||
|
|
||||||
mod p1278_palindrome_partitioning_iii;
|
mod p1278_palindrome_partitioning_iii;
|
||||||
|
|
||||||
|
mod p1745_palindrome_partitioning_iv;
|
||||||
|
|
46
src/problem/p1745_palindrome_partitioning_iv.rs
Normal file
46
src/problem/p1745_palindrome_partitioning_iv.rs
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
/**
|
||||||
|
* [1745] Palindrome Partitioning IV
|
||||||
|
*/
|
||||||
|
pub struct Solution {}
|
||||||
|
|
||||||
|
// submission codes start here
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn check_partitioning(s: String) -> bool {
|
||||||
|
let s = s.as_bytes();
|
||||||
|
let length = s.len();
|
||||||
|
|
||||||
|
let mut palindrome = vec![vec![true; length]; length];
|
||||||
|
|
||||||
|
for span in 2..=length {
|
||||||
|
for i in 0..=length - span {
|
||||||
|
let j = i + span - 1;
|
||||||
|
palindrome[i][j] = palindrome[i + 1][j - 1] && (s[i] == s[j])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in 0..length - 2 {
|
||||||
|
// 所有字符串都必须是非空的
|
||||||
|
for j in i + 2..length {
|
||||||
|
if palindrome[0][i] && palindrome[i + 1][j - 1] && palindrome[j][length - 1] {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// submission codes end
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_1745() {
|
||||||
|
assert!(Solution::check_partitioning("abcbdd".to_owned()));
|
||||||
|
assert!(!Solution::check_partitioning("bcbddxy".to_owned()));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user