2326. Spiral Matrix IV Medium
1/**
2 * [2326] Spiral Matrix IV
3 *
4 * You are given two integers m and n, which represent the dimensions of a matrix.
5 * You are also given the head of a linked list of integers.
6 * Generate an m x n matrix that contains the integers in the linked list presented in spiral order (clockwise), starting from the top-left of the matrix. If there are remaining empty spaces, fill them with -1.
7 * Return the generated matrix.
8 *
9 * Example 1:
10 * <img alt="" src="https://assets.leetcode.com/uploads/2022/05/09/ex1new.jpg" style="width: 240px; height: 150px;" />
11 * Input: m = 3, n = 5, head = [3,0,2,6,8,1,7,9,4,2,5,5,0]
12 * Output: [[3,0,2,6,8],[5,0,-1,-1,1],[5,2,4,9,7]]
13 * Explanation: The diagram above shows how the values are printed in the matrix.
14 * Note that the remaining spaces in the matrix are filled with -1.
15 *
16 * Example 2:
17 * <img alt="" src="https://assets.leetcode.com/uploads/2022/05/11/ex2.jpg" style="width: 221px; height: 60px;" />
18 * Input: m = 1, n = 4, head = [0,1,2]
19 * Output: [[0,1,2,-1]]
20 * Explanation: The diagram above shows how the values are printed from left to right in the matrix.
21 * The last space in the matrix is set to -1.
22 *
23 * Constraints:
24 *
25 * 1 <= m, n <= 10^5
26 * 1 <= m * n <= 10^5
27 * The number of nodes in the list is in the range [1, m * n].
28 * 0 <= Node.val <= 1000
29 *
30 */
31pub struct Solution {}
32use crate::util::linked_list::{ListNode, to_list};
33
34// problem: https://leetcode.com/problems/spiral-matrix-iv/
35// discuss: https://leetcode.com/problems/spiral-matrix-iv/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39// Definition for singly-linked list.
40// #[derive(PartialEq, Eq, Clone, Debug)]
41// pub struct ListNode {
42// pub val: i32,
43// pub next: Option<Box<ListNode>>
44// }
45//
46// impl ListNode {
47// #[inline]
48// fn new(val: i32) -> Self {
49// ListNode {
50// next: None,
51// val
52// }
53// }
54// }
55impl Solution {
56 pub fn spiral_matrix(m: i32, n: i32, head: Option<Box<ListNode>>) -> Vec<Vec<i32>> {
57 vec![]
58 }
59}
60
61// submission codes end
62
63#[cfg(test)]
64mod tests {
65 use super::*;
66
67 #[test]
68 fn test_2326() {
69 }
70}
71
Back
© 2025 bowen.ge All Rights Reserved.