avatar
文章
590
标签
104
分类
17

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

byu_rself

LC.P1834[单线程CPU]
发表于2023-05-07|更新于2023-05-07|LeetCode|数组•优先队列
LC.P1834[单线程CPU] 方法一:排序+优先队列1234567891011121314151617181920212223242526272829class Solution { public int[] getOrder(int[][] tasks) { int n = tasks.length; int[] ans = new int[n]; int[][] index = new int[n][3]; // {入队时间,执行时间,原任务编号} for (int i = 0; i < n; ++i) index[i] = new int[]{tasks[i][0], tasks[i][1], i}; Arrays.sort(index, (a, b) -> a[0] - b[0]); // 按入队时间进行升序 // 先按 执行时间 排序,再按 任务编号 排序 PriorityQueue<int[ ...
LC.P1010[总持续时间可被60整除的歌曲]
发表于2023-05-07|更新于2023-05-07|LeetCode|数学•数组
LC.P1010[总持续时间可被60整除的歌曲] 方法一:数学1234567891011121314class Solution { public int numPairsDivisibleBy60(int[] time) { int[] cnt = new int[60]; int ans = 0; for (int i : time) { i %= 60; int j = (60 - i) % 60; // 先查询再更新,题目要求 i < j ans += cnt[j]; ++cnt[i]; } return ans; }} 时间复杂度:$O(n)$ 空间复杂度:$O(M)$,$M = 60$
LC.P373[查找和最小的K对数字]
发表于2023-05-06|更新于2023-12-08|LeetCode|数组•堆•优先队列•小根堆
LC.P373[查找和最小的K对数字] 方法一:优先队列123456789101112131415class Solution { public List<List<Integer>> kSmallestPairs(int[] nums1, int[] nums2, int k) { PriorityQueue<int[]> q = new PriorityQueue<>((a, b) -> (nums1[a[0]] + nums2[a[1]]) - (nums1[b[0]] + nums2[b[1]])); for (int i = 0; i < Math.min(nums1.length, k); ++i) { q.offer(new int[]{i, 0}); } List<List<Integer>> ans = new ArrayList<> ...
LC.P1419[数青蛙]
发表于2023-05-06|更新于2023-05-07|LeetCode|模拟
LC.P1419[数青蛙] 方法一:计数+模拟123456789101112131415161718192021222324252627class Solution { public int minNumberOfFrogs(String croakOfFrogs) { int c = 0, r = 0, o = 0, a = 0, k = 0, ans = 0; for (char x : croakOfFrogs.toCharArray()) { if (x == 'c') { if (k > 0) --k; else ++ans; ++c; } else if (x == 'r') { --c; ++r; } else ...
LC.P641[设计循环双端队列]
发表于2023-05-05|更新于2023-05-05|LeetCode|数组•双指针•构造•循环双端队列
LC.P641[设计循环双端队列] 方法一:双指针+数组1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071class MyCircularDeque { int[] data; int size, head, tail; public MyCircularDeque(int k) { data = new int[k]; size = 0; head = 0; tail = k - 1; } public boolean insertFront(int value) { if (isFull()) return false; head = head == 0 ? data.length - 1 : head - 1; // ...
LC.P432[全O(1)的数据结构]
发表于2023-05-05|更新于2023-05-05|LeetCode|哈希表•构造•双向链表
LC.P432[全O(1)的数据结构] 方法一:双向链表+哈希表123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108class AllOne { Node head, tail; Map<String, Node> map; public AllOne() { map = new HashMap<>(); head = new Node(-1); tail = new Node(-1); head.next = tail; tail.prev = head; } ...
LC.P2432[处理用时最长的那个任务的员工]
发表于2023-05-05|更新于2023-05-05|LeetCode|数组
LC.P2432[处理用时最长的那个任务的员工] 方法一:直接遍历123456789101112131415class Solution { public int hardestWorker(int n, int[][] logs) { int ans = 0, max = 0, last = 0; for (int[] log : logs) { int id = log[0], time = log[1]; time -= last; if (max < time || (max == time && ans > id)) { max = time; ans = id; } last += time; } return ans; }} 时 ...
LC.P146[LRU缓存]
发表于2023-05-04|更新于2023-09-24|LeetCode|哈希表•链表•LRU•双向链表
LC.P146[LRU缓存] 方法一:手写LRU12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970class LRUCache { private static class Node { int key, value; Node prev, next; Node(int key, int value) { this.key = key; this.value = value; } } int capacity; Node dummy = new Node(0, 0); // 哨兵节点 Map<Integer, Node> map = new HashMap<>(); pu ...
LC.P2106[摘水果]
发表于2023-05-04|更新于2023-05-04|LeetCode|双指针
LC.P2106[摘水果] 方法一:双指针1234567891011121314class Solution { public int maxTotalFruits(int[][] fruits, int startPos, int k) { int ans = 0, sum = 0; for (int i = 0, j = 0; j < fruits.length; ++j) { int pos = fruits[j][0], cnt = fruits[j][1]; sum += cnt; while (i <= j && pos - fruits[i][0] + Math.min(Math.abs(startPos - fruits[i][0]), Math.abs(startPos - pos)) > k) { sum -= fruits[i++][1]; ...
LC.P460[LFU缓存]
发表于2023-05-03|更新于2023-09-25|LeetCode|哈希表•链表•双向链表•LFU
LC.P460[LFU缓存] 方法一:哈希表+双向链表12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091class LFUCache { Map<Integer, Node> keyToNode = new HashMap<>(); Map<Integer, Node> freqToDummy = new HashMap<>(); int capacity; int minFreq; public LFUCache(int capacity) { this.capacity = capacity; } public int get(int key) { ...
1…484950…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!
搜索
数据库加载中