LeetCode - Rotate Image
Question Definition
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
More …You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
More …Implement a MyCalendar class to store your events. A new event can be added if adding the event will not cause a double booking.
Your class will have the method, book(int start, int end). Formally, this represents a booking on the half open interval [start, end), the range of real numbers x such that start <= x < end.
A double booking happens when two events have some non-empty intersection (ie., there is some time that is common to both events.)
For each call to the method MyCalendar.book, return true if the event can be added to the calendar successfully without causing a double booking. Otherwise, return false and do not add the event to the calendar.
Your class will be called like this: MyCalendar cal = new MyCalendar(); MyCalendar.book(start, end)
More …Given two integer arrays A and B, return the maximum length of an subarray that appears in both arrays.
Example 1:
Input:
A: [1,2,3,2,1]
B: [3,2,1,4,7]
Output: 3
Explanation:
The repeated subarray with maximum length is [3, 2, 1].
Note:
A[i]
, B[i]
< 100
public int findLength(int[] A, int[] B) {
int[][] dp = new int[A.length + 1][B.length + 1];
int max = 0;
for(int i = A.length - 1; i >= 0; i--){
for(int j = B.length - 1; j >= 0; j--){
if(A[i] == B[j]){
dp[i][j] = dp[i + 1][j + 1] + 1;
if(dp[i][j] > max)
max = dp[i][j];
}else
dp[i][j] = 0;
}
}
return max;
}
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.
More …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.
You may assume no duplicate exists in the array.
More …