数组
。。
押切徹
这个作者很懒,什么都没留下…
展开
-
LeetCode 31.Next Permutation Medium/Array
文章目录1.Description2.Example3.Solution 1.Description Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such an arrangement is not possible, it must rearrange it as the lowest possible ord原创 2020-11-12 16:52:21 · 110 阅读 · 0 评论 -
LeetCode 73. Set Matrix Zeroes(矩阵置零) 数组/medium
文章目录1.Description2.Example3.Solution1.使用标记数组2.使用两个标记变量 1.Description 给定一个 m x n 的矩阵,如果一个元素为 0 ,则将其所在行和列的所有元素都设为 0 。请使用 原地 算法。 进阶: 一个直观的解决方案是使用 O(mn) 的额外空间,但这并不是一个好的解决方案。 一个简单的改进方案是使用 O(m + n) 的额外空间,但这仍然不是最好的解决方案。 你能想出一个仅使用常量空间的解决方案吗? 2.Example 输入:matri原创 2021-03-21 19:21:38 · 121 阅读 · 0 评论 -
59. Spiral Matrix II(螺旋矩阵2) 数组/medium
文章目录1.Description2.Example3.Solution 1.Description 给你一个正整数 n ,生成一个包含 1 到 n2 所有元素,且元素按顺时针顺序螺旋排列的 n x n 正方形矩阵 matrix 。 2.Example 输入:n = 3 输出:[[1,2,3],[8,9,4],[7,6,5]] 3.Solution 一圈一圈地分别遍历矩阵的上、右、下、左四个边。设定一个seed值,毎向前移动一格就自增1. class Solution { public i原创 2021-03-16 19:24:18 · 47 阅读 · 0 评论 -
54. Spiral Matrix(螺旋数组) 数组/medium
文章目录1.Description2.Example3.Solution 1.Description 给你一个 m 行 n 列的矩阵 matrix ,请按照 顺时针螺旋顺序 ,返回矩阵中的所有元素。 2.Example 输入: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] 3.Solution 一层一层地向内遍历,通过四个for循环分别遍历上、右、下、左。 class Solution {原创 2021-03-15 22:53:46 · 90 阅读 · 0 评论 -
LeetCode 766.Toeplitz Matrix(托普利茨矩阵) 数组/easy
文章目录1.Description2.Example3.Solution 1.Description 给你一个 m x n 的矩阵 matrix 。如果这个矩阵是托普利茨矩阵,返回 true ;否则,返回 false 。 如果矩阵上每一条由左上到右下的对角线上的元素都相同,那么这个矩阵是 托普利茨矩阵 。 2.Example 输入:matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]] 输出:true 解释: 在上述矩阵中, 其对角线为: "[9]", "[5, 5]",原创 2021-02-25 15:35:09 · 77 阅读 · 0 评论 -
LeetCode 832.翻转图像 数组/easy
文章目录1.Description2.Example3.Solution 1.Description 给定一个二进制矩阵 A,我们想先水平翻转图像,然后反转图像并返回结果。 水平翻转图片就是将图片的每一行都进行翻转,即逆序。例如,水平翻转 [1, 1, 0] 的结果是 [0, 1, 1]。 反转图片的意思是图片中的 0 全部被 1 替换, 1 全部被 0 替换。 2.Example 输入:[[1,1,0],[1,0,1],[0,0,0]] 输出:[[1,0,0],[0,1,0],[1,1,1]] 解释:原创 2021-02-24 14:56:54 · 97 阅读 · 0 评论 -
LeetCode 119.Pascal‘s Triangle II(杨辉三角II) 数组,数学/easy
文章目录1.Description2.Example3.Solution法一:递推(时间复杂度都是平方)2.线性递推(时间复杂度为k) 1.Description 给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行。 在杨辉三角中,每个数是它左上方和右上方的数的和。 2.Example 输入: 3 输出: [1,3,3,1] 3.Solution https://leetcode-cn.com/problems/pascals-triangle-ii/solution/yang-h原创 2021-02-12 14:58:14 · 93 阅读 · 0 评论