3311. 构造符合图结构的二维矩阵

This commit is contained in:
li-chx
2025-09-08 21:57:43 +08:00
parent 817cef54c7
commit f82b9e1b8c
2 changed files with 166 additions and 16 deletions
+25
View File
@@ -0,0 +1,25 @@
pub fn make_arr(s: &str) -> Vec<Option<i32>> {
s.trim_matches(&['[', ']'][..])
.split(',')
.map(|x| {
let x = x.trim();
if x == "null" {
None
} else {
Some(x.parse::<i32>().unwrap())
}
})
.collect()
}
pub fn make_matrix(s: &str) -> Vec<Vec<i32>> {
s.trim_matches(&['[', ']'][..])
.split("],[")
.map(|row| {
row.trim_matches(&['[', ']'][..])
.split(',')
.map(|x| x.trim().parse::<i32>().unwrap())
.collect()
})
.collect()
}