Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

54. 螺旋矩阵 #19

Open
webVueBlog opened this issue Aug 30, 2022 · 4 comments
Open

54. 螺旋矩阵 #19

webVueBlog opened this issue Aug 30, 2022 · 4 comments

Comments

@webVueBlog
Copy link
Owner

54. 螺旋矩阵

Description

Difficulty: 中等

Related Topics: 数组, 矩阵, 模拟

给你一个 mn 列的矩阵 matrix ,请按照 顺时针螺旋顺序 ,返回矩阵中的所有元素。

示例 1:

输入:matrix = [[1,2,3],[4,5,6],[7,8,9]]
输出:[1,2,3,6,9,8,7,4,5]

示例 2:

输入:matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
输出:[1,2,3,4,8,12,11,10,9,5,6,7]

提示:

  • m == matrix.length
  • n == matrix[i].length
  • 1 <= m, n <= 10
  • -100 <= matrix[i][j] <= 100

Solution

Language: JavaScript

/**
 * @param {number[][]} matrix
 * @return {number[]}
 */
var spiralOrder = function(matrix) {
    let n = []
    while (matrix.length) {
        n = _.concat(n, matrix.shift())
        matrix = _.reverse(_.zip(...matrix))
    }
    return n
};
@nekobc1998923
Copy link

这里的 _. 是什么呀?

@webVueBlog
Copy link
Owner Author

这里的 _. 是什么呀?

_是一个变量名。 这里是一个全局变量。

@nekobc1998923
Copy link

_是一个变量名。 这里是一个全局变量。

请问是在哪定义的呢,有文档吗找不到 QAQ

@alileew
Copy link

alileew commented Sep 8, 2022

_是一个变量名。 这里是一个全局变量。

请问是在哪定义的呢,有文档吗找不到 QAQ

这里 _.xxx 肯定对应的是全局的 lodash 函数

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants