Leetcode
https://leetcode.com/problems/rotate-image/
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.
Example 1:
Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]
Output: [[7,4,1],[8,5,2],[9,6,3]]
Example 2:
Input: matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]
Output: [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]
Example 3:
Input: matrix = [[1]]
Output: [[1]]
Example 4:
Input: matrix = [[1,2],[3,4]]
Output: [[3,1],[4,2]]
Constraints:
Time Complexity:
Space Complexity:
void rotate(int** matrix, int matrixSize, int* matrixColSize){
for(int i=0; i<(matrixSize+1)/2; i++){
int k = matrixSize-i-1;
for(int j=0; j<matrixSize/2; j++){
int l = matrixSize-j-1;
//rotate 90 degrees
int temp = matrix[i][j];
matrix[i][j] = matrix[l][i];
matrix[l][i] = matrix[k][l];
matrix[k][l] = matrix[j][k];
matrix[j][k] = temp;
}
}
}
https://leetcode.com/problems/house-robber/ Description You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night. Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police. Example 1: Input: nums = [1,2,3,1]
Dec 9, 2020https://leetcode.com/problems/coin-change/ Description You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1. You may assume that you have an infinite number of each kind of coin. Example 1: Input: coins = [1,2,5], amount = 11
Dec 7, 2020https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x/ Description You are given an array nums of non-negative integers. nums is considered special if there exists a number x such that there are exactly x numbers in nums that are greater than or equal to x. Notice that x does not have to be an element in nums. Return x if the array is special, otherwise, return -1. It can be proven that if nums is special, the value for x is unique. Example 1:
Dec 7, 2020https://leetcode.com/problems/validate-stack-sequences/ Description Given two sequences pushed and popped with distinct values, return true if and only if this could have been the result of a sequence of push and pop operations on an initially empty stack. Example 1: Input: pushed = [1,2,3,4,5], popped = [4,5,3,2,1] Output: true Explanation: We might do the following sequence:
Dec 7, 2020or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up