3311. 构造符合图结构的二维矩阵
This commit is contained in:
+25
@@ -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()
|
||||
}
|
||||
Reference in New Issue
Block a user