Ganz toll
ruo砚
以前的代码还真的是忘得一干二净
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
【LeetCode 1004】最大连续1的个数 III
思路滑动窗口,一次通过! public int longestOnes(int[] nums, int k) { int maxL = 0; int start = 0; int end = 0; int cnt = 0; while (end < nums.length) { if (nums[end] == 0) cnt++; while (cnt > k) {原创 2022-04-05 18:34:43 · 442 阅读 · 0 评论 -
【LeetCode 200】岛屿数量
思路深度优先搜索(一次做出来的!) public static int numIslands(char[][] grid) { int ret = 0; // grid是一个m行n列的矩阵 int m = grid.length; int n = grid[0].length; boolean[][] visited = new boolean[m][n]; int[] directions = {-1, 0, 1};原创 2022-04-05 15:52:55 · 373 阅读 · 0 评论 -
【LeetCode 100】相同的树
深度优先搜索 public boolean isSameTree(TreeNode p, TreeNode q) { if (p == null && q == null) return true; if (p == null || q == null) return false; if (p.val != q.val) return false; return isSameTree(p.left, q.left)原创 2022-03-31 15:16:55 · 507 阅读 · 0 评论 -
【LeetCode 611】有效三角形的个数
public static int triangleNumber(int[] nums) { int ret = 0; Arrays.sort(nums); int n = nums.length; for (int i = 0; i < n-1; i++) for (int j = i + 1; j < n; j++) { // range (nums[j] - nums[i], nums[i] + nums[j])原创 2022-02-27 15:56:37 · 129 阅读 · 0 评论 -
【LeetCode 275】H 指数 II
public static int hIndex(int[] citations) { int n = citations.length; if (citations[n - 1] == 0) return 0; int l = 0; int r = n - 1; while (l < r) { // find the citations[mid] <= n - mid int mid = l + (...原创 2022-02-25 15:42:17 · 210 阅读 · 0 评论 -
【LeetCode 58】最后一个单词的长度
LeetCode 58原创 2022-01-06 09:45:10 · 102 阅读 · 0 评论 -
【LeetCode 54,59】螺旋矩阵
LeetCode 54, 59原创 2022-01-04 15:28:50 · 286 阅读 · 0 评论 -
【LeetCode 53】最大子数组和
【LeetCode 53】原创 2022-01-04 10:30:31 · 417 阅读 · 0 评论 -
【LeetCode 49】字母异位词分组
比较复杂的方法。 public static List<List<String>> groupAnagrams(String[] strs) { List<List<String>> list = new ArrayList<List<String>>(); int n = strs.length; if (n == 0) return null; int[] pointers原创 2021-12-31 14:27:17 · 230 阅读 · 0 评论 -
【LeetCode41】缺失的第一个正数
根据参考答案给出的一点提示,完成代码。 public static int firstMissingPositive(int[] nums) { int ret = 1; boolean flag = false; int posCount = 0; for (int i = 0; i < nums.length; i++) if (nums[i] > 0) posCount++; for (int i = 0原创 2021-12-23 20:43:21 · 223 阅读 · 0 评论
分享