119. 杨辉三角 II
问题描述:
代码:
class Solution {
public List getRow(int rowIndex) {
List> list = new ArrayList<>();
for(int i=0;i<=rowIndex;i++){
Listt=new ArrayList<>();
for(int j=0;j<=i;j++){
if(j==0||j==i){
t.add(1);
}else{
t.add(list.get(i-1).get(j-1)+list.get(i-1).get(j));
}
}
list.add(t);
}
return list.get(rowIndex);
}
}
思路:
动态规划
48. 旋转图像
问题描述:
代码:
class Solution {
public void rotate(int[][] matrix) {
int n = matrix.length;
for(int i=0;i
思路:
经历两次反转 先水平翻转 再对角线翻转
数学推理:
59. 螺旋矩阵 II
问题描述:
class Solution {
public int[][] generateMatrix(int n) {
int top=0,bottom=n-1,left=0,right=n-1;
int index=1;
int [][]matrix=new int[n][n];
while(index<=n*n){
for(int i=left;i<=right;i++){
matrix[top][i]=index++;
}
top++;
for(int j=top;j<=bottom;j++){
matrix[j][right]=index++;
}
right--;
for(int p=right;p>=left;p--){
matrix[bottom][p]=index++;
}
bottom--;
for(int q=bottom;q>=top;q--){
matrix[q][left]=index++;
}
left++;
}
return matrix;
}
}
思路:
上右下左的顺序 依次填数 每结束一个for循环 更新相应的边界值



