
数组
文章平均质量分 71
TIMELIMITE
Time is not enough. I must hurry up !
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode 56 合并区间
// LeetCode 56 合并区间 // 二维排序,依次取出区间进行比较,O(nlogn))复杂度 class Solution { public int[][] merge(int[][] intervals) { int n = intervals.length; if (n == 0) return new int[0][0]; ...原创 2019-08-23 16:31:33 · 212 阅读 · 0 评论 -
LeetCode 54 螺旋矩阵
// LeetCode 54 螺旋矩阵 // 分情况讨论,注意终止条件,奇偶统一,用上取整 class Solution { public List<Integer> spiralOrder(int[][] matrix) { if (matrix.length == 0) return new ArrayList<>(); Li...原创 2019-08-22 20:29:40 · 319 阅读 · 0 评论 -
LeetCode 81 搜索旋转排序数组 II
// 找出旋转点,二分 class Solution { public boolean search(int[] nums, int target) { int sep = -1; int n = nums.length; for (int i = 0;i < n - 1; i++){ if (nums[i]...原创 2019-08-25 19:22:50 · 301 阅读 · 0 评论 -
LeetCode 80 删除排序数组中的重复项 II
// 记下重复的第二次 class Solution { public int removeDuplicates(int[] nums) { int n = nums.length; if (n == 0) return 0; int count = 0; boolean flag = false; in...原创 2019-08-25 19:09:25 · 195 阅读 · 0 评论 -
LeetCode 79 单词搜索
// 记录起点,然后dfs class Solution { int[] dx = {-1 , 0, 1, 0}; int[] dy = {0, 1, 0, -1}; int n; int m; boolean[][] vis; public boolean exist(char[][] board, String word) { ...原创 2019-08-25 18:43:24 · 260 阅读 · 0 评论 -
LeetCode 78 子集
// 二进制枚举 class Solution { public List<List<Integer>> subsets(int[] nums) { int n = nums.length; List<List<Integer>> res = new ArrayList<>(); ...原创 2019-08-25 15:00:24 · 275 阅读 · 0 评论 -
LeetCode 75 颜色分类 荷兰国旗问题
// 双下标,begin和end表示中间白色的开始和末尾.再对每个元素进行遍历, // 设为current.分情况讨论: // 当前是红色: 需要跟begin位置进行交换,begin++, current++; // 当前是白色: 保持不变,current++; // 当前是蓝色: 与end位置进行交换,end--,但此时current可能是0, 1, 2,所以保持不变 // 开始想错了,三个...原创 2019-08-25 14:38:47 · 316 阅读 · 0 评论 -
LeetCode 74 搜索二维矩阵
// 二分,当成一维数组,下标转换 class Solution { public boolean searchMatrix(int[][] matrix, int target) { int n = matrix.length; if (n == 0) return false; int m = matrix[0].length; ...原创 2019-08-25 12:19:54 · 273 阅读 · 0 评论 -
LeetCode 66 加一
// 简易版的大数加法模拟 class Solution { public int[] plusOne(int[] digits) { int c = 1; int n = digits.length; int temp; for (int i = n - 1; i >= 0 ;i --){ ...原创 2019-08-24 16:59:09 · 202 阅读 · 0 评论 -
LeetCode 64 最小路径和
// dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + dp[i][j]; // 注意初始化横竖累和 class Solution { public int minPathSum(int[][] grid) { int n = grid.length; int m = grid[0].length; ...原创 2019-08-24 16:33:31 · 273 阅读 · 0 评论 -
LeetCode 63 不同路径II
// 跟62差不多 https://blog.youkuaiyun.com/TIMELIMITE/article/details/100053683 // 就是对当前格子判断下,初始化的时候横竖碰到1就不能走了 class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { int n = ...原创 2019-08-24 16:18:04 · 174 阅读 · 0 评论 -
LeetCode 59 螺旋矩阵II
// LeetCode 59 螺旋矩阵II // 分情况套路,比n*m的简单,注意奇偶 class Solution { public int[][] generateMatrix(int n) { int[][] res = new int[n][n]; int k = 0; int count = 1; while(...原创 2019-08-24 15:13:46 · 309 阅读 · 0 评论 -
LeetCode 55 跳跃游戏
// LeetCode 55 跳跃游戏 // 贪心地每次走最远 class Solution { public boolean canJump(int[] nums) { int currentEnd = 0; int currentFar = 0; boolean res = false; for (int i =...原创 2019-08-22 20:47:15 · 367 阅读 · 0 评论