You are given an n x n 2D matrix
representing an image, rotate the image by 90 degrees (clockwise).
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.
Continue reading “[Leetcode]48. Rotate Image” [Leetcode]739. Daily Temperatures
Given a list of daily temperaturesContinue reading “[Leetcode]739. Daily Temperatures”T
, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put0
instead. For example, given the list of temperaturesT = [73, 74, 75, 71, 69, 72, 76, 73]
, your output should be[1, 1, 4, 2, 1, 1, 0, 0]
. Note: The length oftemperatures
will be in the range[1, 30000]
. Each temperature will be an integer in the range[30, 100]
.
[Leetcode]835. Image Overlap
Two imagesContinue reading “[Leetcode]835. Image Overlap”A
andB
are given, represented as binary, square matrices of the same size. (A binary matrix has only 0s and 1s as values.) We translate one image however we choose (sliding it left, right, up, or down any number of units), and place it on top of the other image. After, the overlap of this translation is the number of positions that have a 1 in both images. (Note also that a translation does not include any kind of rotation.) What is the largest possible overlap? Notes:1 <= A.length = A[0].length = B.length = B[0].length <= 30
0 <= A[i][j], B[i][j] <= 1
[Leetcode]283. Move Zeroes
Given an arrayContinue reading “[Leetcode]283. Move Zeroes”nums
, write a function to move all0
's to the end of it while maintaining the relative order of the non-zero elements. Note: You must do this in-place without making a copy of the array. Minimize the total number of operations.
[Leetcode]31. Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order). The replacement must be in-place and use only constant extra memory. Here are some examples. Inputs are in the left-hand column and its corresponding outputs are in the right-hand column.Continue reading “[Leetcode]31. Next Permutation”1,2,3
→1,3,2
3,2,1
→1,2,3
1,1,5
→1,5,1
[Leetcode]238. Product of Array Except Self
Given an arrayContinue reading “[Leetcode]238. Product of Array Except Self”nums
of n integers where n > 1, return an arrayoutput
such thatoutput[i]
is equal to the product of all the elements ofnums
exceptnums[i]
. Note: Please solve it without division and in O(n). Follow up: Could you solve it with constant space complexity? (The output array does not count as extra space for the purpose of space complexity analysis.) Example: Input:[1,2,3,4]
Output:[24,12,8,6]
[Leetcode]442. Find All Duplicates in an Array
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements that appear twice in this array. Could you do it without extra space and in O(n) runtime?Continue reading “[Leetcode]442. Find All Duplicates in an Array”
[Leetcode]1508. Range Sum of Sorted Subarray Sums
Given the arrayContinue reading “[Leetcode]1508. Range Sum of Sorted Subarray Sums”nums
consisting ofn
positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array ofn * (n + 1) / 2
numbers. Return the sum of the numbers from indexleft
to indexright
(indexed from 1), inclusive, in the new array. Since the answer can be a huge number return it modulo 10^9 + 7.