Leetcode - Arrays | Rotate
48. Rotate Image[M]
https://leetcode.com/problems/rotate-image/
Description
ou are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
Note:
You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.
Example 1:
1 | Given input matrix = |
Example 2:
1 | Given input matrix = |
Solution
1 |
81. Search in Rotated Sorted Array II[M]
https://leetcode.com/problems/search-in-rotated-sorted-array-ii/
Description
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
(i.e., [0,0,1,2,2,5,6] might become [2,5,6,0,0,1,2]).
You are given a target value to search. If found in the array return true, otherwise return false.
Example 1:
1 | Input: nums = [2,5,6,0,0,1,2], target = 0 |
Example 2:
1 | Input: nums = [2,5,6,0,0,1,2], target = 3 |
Follow up:
- This is a follow up problem to Search in Rotated Sorted Array, where
numsmay contain duplicates. - Would this affect the run-time complexity? How and why?
Solution
154. Find Minimum in Rotated Sorted Array II[H]
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/
Description
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).
Find the minimum element.
The array may contain duplicates.
Example 1:
1 | Input: [1,3,5] |
Example 2:
1 | Input: [2,2,2,0,1] |
Note:
- This is a follow up problem to Find Minimum in Rotated Sorted Array.
- Would allow duplicates affect the run-time complexity? How and why?
Solution
1 |
733. Flood Fill[E]
https://leetcode.com/problems/flood-fill/
Description
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image (from 0 to 65535).
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.
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.
At the end, return the modified image.
Example 1:
1 | Input: |
Note:
The length of image and image[0] will be in the range [1, 50].
The given starting pixel will satisfy 0 <= sr < image.length and 0 <= sc < image[0].length.
The value of each color in image[i][j] and newColor will be an integer in [0, 65535].
Solution
https://leetcode.com/problems/flood-fill/solution/
1 |





