avatar
文章
590
标签
104
分类
17

首页
归档
标签
分类
友链
日志
byu_rself
搜索
首页
归档
标签
分类
友链
日志

byu_rself

LC.P729[我的日程安排表I]
发表于2023-09-26|更新于2023-09-26|LeetCode|数组•模拟•线段树
LC.P729[我的日程安排表I] 方法一:模拟12345678910111213141516171819202122232425class MyCalendar { List<int[]> booked; public MyCalendar() { booked = new ArrayList<int[]>(); } public boolean book(int start, int end) { for (int[] arr : booked) { int left = arr[0], right = arr[1]; if (left < end && start < right) { return false; } } booked.add(new int[]{st ...
LC.P2582[递枕头]
发表于2023-09-26|更新于2023-09-26|LeetCode|数学•模拟
LC.P2582[递枕头] 方法一:模拟123456789101112class Solution { public int passThePillow(int n, int time) { int ans = 1, k = 1; while (time-- > 0) { ans += k; if (ans == 1 || ans == n) { k *= -1; } } return ans; }} 时间复杂度:$O(time)$ 空间复杂度:$O(1)$ 方法二:数学1234567class Solution { public int passThePillow(int n, int time) { int k = time / (n - 1); int mod = time ...
LC.P211[添加与搜索单词-数据结构设计]
发表于2023-09-25|更新于2023-09-25|LeetCode|DFS•前缀树•字典树•Trie
LC.P211[添加与搜索单词-数据结构设计] 方法一:Trie+DFS1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465class WordDictionary { Trie trie; public WordDictionary() { trie = new Trie(); } public void addWord(String word) { trie.add(word); } public boolean search(String word) { return dfs(word, 0, trie); } private boolean dfs(String word, int index, Trie node) { ...
LC.P1993[树上的操作]
发表于2023-09-23|更新于2023-09-25|LeetCode|DFS•树•模拟•二叉树
LC.P1993[树上的操作] 方法一:DFS1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071class LockingTree { int[] locked; int[] parent; List<Integer>[] children; public LockingTree(int[] parent) { int n = parent.length; locked = new int[n]; this.parent = parent; children = new List[n]; Arrays.fill(locked, -1); Arrays.setAll(children, k -> new ArrayList<& ...
LC.P2246[相邻字符不同的最长路径]
发表于2023-09-22|更新于2023-09-22|LeetCode|DFS•动态规划•树
LC.P2246[相邻字符不同的最长路径] 方法一:树形DP12345678910111213141516171819202122232425262728class Solution { List<Integer>[] g; String s; int ans; public int longestPath(int[] parent, String s) { this.s = s; int n = parent.length; g = new ArrayList[n]; Arrays.setAll(g, k -> new ArrayList<>()); for (int i = 1; i < n; ++i) g[parent[i]].add(i); dfs(0); return ans + 1; } private int dfs(int x) { int ...
LC.P2591[将钱分给最多的儿童]
发表于2023-09-22|更新于2023-09-22|LeetCode|数学•贪心
LC.P2591[将钱分给最多的儿童] 方法一:分类讨论12345678class Solution { public int distMoney(int money, int children) { if (money < children) return -1; if (money > 8 * children) return children - 1; if (money == 8 * children - 4) return children - 2; return (money - children) / 7; }} 时间复杂度:$O(1)$ 空间复杂度:$O(1)$
LC.P124[二叉树中的最大路径和]
发表于2023-09-21|更新于2023-09-21|LeetCode|DFS•树•二叉树
LC.P124[二叉树中的最大路径和] 方法一:DFS1234567891011121314151617181920212223242526272829303132333435/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, TreeNode right) { * this.val = val; * this.left = left; * this.right = right; * } * } */class Solution { ...
LC.P2603[收集树中金币]
发表于2023-09-21|更新于2023-09-21|LeetCode|树•拓扑排序
LC.P2603[收集树中金币] 方法一:拓扑排序123456789101112131415161718192021222324252627282930313233343536373839404142434445464748class Solution { public int collectTheCoins(int[] coins, int[][] edges) { int n = coins.length; List<Integer>[] g = new ArrayList[n]; Arrays.setAll(g, e -> new ArrayList<>()); int[] degree = new int[n]; for (int[] e : edges) { int x = e[0], y = e[1]; g[x].add(y); g[y].add(x); ...
LCP.P6[拿硬币]
发表于2023-09-20|更新于2023-09-20|LeetCodeLCR|数学•模拟
LCP.P6[拿硬币] 方法一:数学123456789class Solution { public int minCount(int[] coins) { int ans = 0; for (int coin : coins) { ans += (coin + 1) >> 1; } return ans; }} 时间复杂度:$O(n)$ 空间复杂度:$O(1)$
LC.P2560[打家劫舍IV]
发表于2023-09-19|更新于2023-09-20|LeetCode|动态规划•数组•二分查找•贪心
LC.P2560[打家劫舍IV] 方法一:二分查找+动态规划12345678910111213141516171819202122232425262728class Solution { public int minCapability(int[] nums, int k) { int left = 0, right = 0; for (int x : nums) { right = Math.max(right, x); } while (left < right) { int mid = left + right >>> 1; if (check(nums, k, mid)) right = mid; else left = mid + 1; } return right; } private bool ...
1…161718…59
avatar
byu_rself
努力努力!
文章
590
标签
104
分类
17
Follow Me
最新文章
LC.P416[分割等和子集]2025-04-07
LC.P2874[有序三元组中的最大值II]2025-04-02
LC.P3128[直角三角形]2024-08-02
LCP.P40[心算挑战]2024-08-01
LC.P3115[质数的最大距离]2024-07-02
分类
  • LeetCode546
    • LCP4
    • LCR13
    • 剑指Offer13
    • 面试题2
  • Linux3
  • 后端9
    • CompletableFuture1
标签
GitDFSGolang动态规划记忆化搜索字符串栈数学数组哈希表滑动窗口链表递归图BFS多源BFS双指针树子数组前缀和前缀树字典树Trie子序列区间DP递推模拟枚举字符串哈希二分查找贪心排序负二进制回溯二叉树状态压缩子串迭代随机化后缀和
归档
  • 四月 20252
  • 八月 20242
  • 七月 20241
  • 五月 20243
  • 四月 20242
  • 三月 202410
  • 二月 202410
  • 一月 202414
网站资讯
文章数目 :
590
已运行时间 :
本站总字数 :
289.3k
本站访客数 :
本站总访问量 :
最后更新时间 :
©2023 - 2025 By byu_rself
框架 Hexo|主题 Butterfly
Hi, welcome to my blog!
搜索
数据库加载中