Algorithem_Matrix
发表于|更新于
|浏览量:
Algorithem_Matrix
题目
Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell.
The distance between two adjacent cells is 1.
Example 1:

1 | Input: mat = [[0,0,0],[0,1,0],[0,0,0]] |
Example 2:

1 | Input: mat = [[0,0,0],[0,1,0],[1,1,1]] |
解法
文章作者: 今是昨非
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 今是昨非的博客!
相关推荐
2022-04-20
Algorithem_Depth-First Search
733. Flood FillAn image is represented by an m x n integer grid image where image[i][j] represents the pixel value of the image. You are also given three integers sr, sc, and newColor. You should perform a flood fill on the image starting from the pixel image[sr][sc]. To perform a flood fill, consider the starting pixel, plus any pixels connected 4-directionally to the starting pixel of the same color as the starting pixel, plus any pixels connected 4-directionally to those pixels (also wit...
2022-04-13
Algorithem_Sort
Algorithem_SortGiven an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order. QuickSort实现逻辑:取指定位置的 index 的值key,比较index和 index之前的数字,如果前面的数字大于后面的数字,则交换位置; 比如: 123456789[ 8 3 5 1 4 2 ]从 index为1开始,当前元素3,前面元素8,8 > 3,故而交换位置,数组还为[ 3 8 5 1 4 2 ]然后 index 为2,当前元素为5,前面元素为8,8>5,故而交换位置,数组为[ 3 5 8 1 4 2 ]然后 index 为3,当前元素为1,前面元素为8,8>1,故而交换位置,数组为[ 3 5 1 8 4 2 ];5>1,故而交换位置,数组为[ 3 1 5 8 4 2 ];3>1,故而交换位置,数组为[ 1 3 5 8 4 2...
2022-04-19
Algorithem_Depth-First Search
Algorithem_Depth-First Search3. Longest Substring Without Repeating CharactersGiven a string s, find the length of the longest substring without repeating characters. Example 1: 123Input: s = "abcabcbb"Output: 3Explanation: The answer is "abc", with the length of 3. Example 2: 123Input: s = "bbbbb"Output: 1Explanation: The answer is "b", with the length of 1. Example 3: 1234Input: s = "pwwkew"Output: 3Explanation: The answer is "wke&q...
2022-04-14
Algorithem_ReverseArray
Algorithem_ReverseArrayGiven an array, rotate the array to the right by k steps, where k is non-negative. Example 1: 12345678Input: nums = [1,2,3,4,5,6,7], k = 3Output: [5,6,7,1,2,3,4]Explanation:rotate 1 steps to the right: [7,1,2,3,4,5,6]rotate 2 steps to the right: [6,7,1,2,3,4,5]rotate 3 steps to the right: [5,6,7,1,2,3,4] Example 2: 1234567Input: nums = [-1,-100,3,99], k = 2Output: [3,99,-1,-100]Explanation: rotate 1 steps to the right: [99,-1,-100,3]rotate 2 steps to the right: [3,9...
2022-04-18
Algorithem_TwoPointersOfLinked List
Algorithem_TwoPointersOfLinked List876. Middle of the Linked ListGiven the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the second middle node. Example 1: 123Input: head = [1,2,3,4,5]Output: [3,4,5]Explanation: The middle node of the list is node 3. Example 2: 123Input: head = [1,2,3,4,5,6]Output: [4,5,6]Explanation: Since the list has two middle nodes with values 3 and 4, we return the second one. 解法单看例子,感觉是获取数组中间位置到末尾,这个...
2022-04-24
Algorithem_PermutationInString
Algorithem_PermutationInStringGiven two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise. In other words, return true if one of s1’s permutations is the substring of s2. Example 1: 1234Input: s1 = "ab", s2 = "eidbaooo"Output: trueExplanation: s2 contains one permutation of s1 ("ba"). Example 2: 12Input: s1 = "ab", s2 = "eidboaoo"Output: false 解法首先理解 Permutation的意思,题目需要的是 s2包含 s1中字符串的任意一种排列,就返回 true,否则返...
公告
This is my Blog