Basic Question
Print Pascal
void solution(int n){
int[] preLevel = new int[]{1};
printPascal(preLevel);
for(int i=2; i<=n; i++){
int[] level = new int[i];
level[0] = 1;
level[i-1] = 1;
// i 為第幾層,有i個element
// j 的長度判斷必須為上一個preLevel的長度
for(int j=0; j<i-2; j++){
level[j+1] = preLevel[j] + preLevel[j+1];
}
printPascal(level);
preLevel = level;
}
}
void printPascal(int[] level){
StringBuilder sb = new StringBuilder();
for(int n: level){
sb.append(n).append(" ");
}
sb.append("\n");
System.out.println(sb.toString());
}48 Rotate Image
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise).
Swap by row (first_row++, last_row--)
Swap elements by diagnals
836 Rectangle Overlap
Given two rectangles, find if the given two rectangles overlap or not.
l1: Top Left coordinate of first rectangle. r1: Bottom Right coordinate of first rectangle. l2: Top Left coordinate of second rectangle. r2: Bottom Right coordinate of second rectangle.
l1 != r2 and l2 != r2
223. Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane. (A, B) is left bottom corner, (C, D) is right top corner
283 Move Zeroes
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. Move in-space without using extra array.
Example:
Input: [0,1,0,3,12] Output: [1,3,12,0,0]
246 Strobogrammatic Number
A strobogrammatic number is a number that looks the same when rotated 180 degrees. Write a function to determine if a number is strobogrammatic
頭尾i+j是否包含在"00 11 88 69 96"
247 Strobogrammatic Number II
Find all strobogrammatic numbers that are of length = n.
Backtracking(n ,n): 第二個n用來判斷邊界是否要放0
Is Prime Number
進制轉換
Last updated
Was this helpful?