You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image (from 0 to 65535).
5
+
6
+
Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image.
7
+
8
+
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 with the same color as the starting pixel), and so on. Replace the color of all of the aforementioned pixels with the newColor.
9
+
10
+
At the end, return the modified image.
11
+
12
+
Example 1:
13
+
Input:
14
+
image = [[1,1,1],[1,1,0],[1,0,1]]
15
+
sr = 1, sc = 1, newColor = 2
16
+
Output: [[2,2,2],[2,2,0],[2,0,1]]
17
+
Explanation:
18
+
From the center of the image (with position (sr, sc) = (1, 1)), all pixels connected
19
+
by a path of the same color as the starting pixel are colored with the new color.
20
+
Note the bottom corner is not colored 2, because it is not 4-directionally connected
21
+
to the starting pixel.
22
+
Note:
23
+
24
+
The length of image and image[0] will be in the range [1, 50].
25
+
The given starting pixel will satisfy 0 <= sr < image.length and 0 <= sc < image[0].length.
26
+
The value of each color in image[i][j] and newColor will be an integer in [0, 65535].
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
7
+
8
+
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
9
+
10
+
How many possible unique paths are there?
11
+
12
+
Example 1:
13
+
14
+
Input: m = 3, n = 2
15
+
Output: 3
16
+
Explanation:
17
+
From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:
18
+
1. Right -> Right -> Down
19
+
2. Right -> Down -> Right
20
+
3. Down -> Right -> Right
21
+
Example 2:
22
+
23
+
Input: m = 7, n = 3
24
+
Output: 28
25
+
26
+
*/
27
+
28
+
// Solution 1
29
+
// This solution is a naive solution implementing a binary tree and visiting each node.
0 commit comments