摘要:
螺旋矩阵 class Solution { public List<Integer> spiralOrder(int[][] matrix) { List<Integer> list = new ArrayList<>(); int m = matrix.length, n = matrix[0]. 阅读全文
摘要:
旋转图像 原地旋转 将正方形的数组切分成一个个圈,然后对这个圈进行移动 class Solution { public void rotate(int[][] matrix) { int n = matrix.length; for(int i = 0; i < n/2; i++){ rotate( 阅读全文
摘要:
解数独 回溯+哈希 使用哈希表记录行、列和块的状态,然后对所有空缺的位置进行0-9的回溯。 class Solution { boolean line[][] = new boolean[9][9]; boolean column[][] = new boolean[9][9]; boolean b 阅读全文
摘要:
输出二叉树 DFS class Solution { List<List<String>> res = new ArrayList<>(); int m, n, height; public List<List<String>> printTree(TreeNode root) { height = 阅读全文
摘要:
丑数 II 优先队列 维护一个优先队列。先取出最小的数字,将其乘以2、3、5,如果发现没有重复的话就装入优先队列中,需要用到set进行去重。 class Solution { public int nthUglyNumber(int n) { Set<Long> set = new HashSet< 阅读全文
摘要:
不同路径 图dp class Solution { public int uniquePaths(int m, int n) { int dp[][] = new int[m][n]; for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ i 阅读全文