avatar
文章
590
标签
104
分类
17

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

byu_rself

LC.P2656[K个元素的最大和]
发表于2023-11-15|更新于2023-11-15|LeetCode|数学•数组•贪心
LC.P2656[K个元素的最大和] 方法一:贪心+数学123456789class Solution { public int maximizeSum(int[] nums, int k) { int x = -1; for (int num : nums) { x = Math.max(x, num); } return k * x + (k - 1) * k / 2; }} 时间复杂度:$O(n)$ 空间复杂度:$O(1)$
LC.P93[复原IP地址]
发表于2023-11-14|更新于2023-11-14|LeetCode|DFS•字符串•回溯
LC.P93[复原IP地址] 方法一:回溯123456789101112131415161718192021222324252627282930313233343536class Solution { List<String> ans = new ArrayList<>(); List<Integer> path = new ArrayList<>(); char[] cs; int n; public List<String> restoreIpAddresses(String s) { cs = s.toCharArray(); n = cs.length; dfs(0); return ans; } private void dfs(int idx) { if (path.size() > 4) return; if (idx == n) { ...
LC.P131[分割回文串]
发表于2023-11-14|更新于2023-11-14|LeetCode|DFS•动态规划•记忆化搜索•字符串•回溯
LC.P131[分割回文串] 方法一:回溯1234567891011121314151617181920212223242526272829303132class Solution { List<List<String>> ans = new ArrayList<>(); List<String> path = new ArrayList<>(); String s; public List<List<String>> partition(String s) { this.s = s; dfs(0); return ans; } private void dfs(int i) { if (i == s.length()) { ans.add(new ArrayList<>(path)); return; ...
LC.P1334[阈值距离内邻居最少的城市]
发表于2023-11-14|更新于2023-11-21|LeetCode|图•dijkstra•Floyd
LC.P1334[阈值距离内邻居最少的城市] 方法一:Dijkstra12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455class Solution { private static final int INF = 0x3f3f3f3f; int[][] g; int n; int[] dist; boolean[] visited; int distanceThreshold; public int findTheCity(int n, int[][] edges, int distanceThreshold) { g = new int[n][n]; this.n = n; dist = new int[n]; visited = new boolean[n]; this.distanceThresho ...
LC.P40[组合总和II]
发表于2023-11-13|更新于2023-11-13|LeetCode|DFS•数组•回溯
LC.P40[组合总和II] 方法一:回溯+剪枝1234567891011121314151617181920212223242526272829class Solution { List<List<Integer>> ans = new ArrayList<>(); List<Integer> path = new ArrayList<>(); int[] candidates; public List<List<Integer>> combinationSum2(int[] candidates, int target) { this.candidates = candidates; Arrays.sort(candidates); dfs(0, target); return ans; } private void dfs(int start, int target) ...
LC.P39[组合总和]
发表于2023-11-13|更新于2024-04-22|LeetCode|DFS•数组•回溯
LC.P39[组合总和] 方法一:朴素回溯123456789101112131415161718192021222324252627class Solution { List<List<Integer>> ans = new ArrayList<>(); List<Integer> path = new ArrayList<>(); int[] candidates; public List<List<Integer>> combinationSum(int[] candidates, int target) { this.candidates = candidates; dfs(0, target); return ans; } private void dfs(int i, int target) { if (i == candidates.length) return ...
LC.P2300[咒语和药水的成功对数]
发表于2023-11-10|更新于2023-11-10|LeetCode|数组•二分查找
LC.P2300[咒语和药水的成功对数] 方法一:排序+二分1234567891011121314151617class Solution { public int[] successfulPairs(int[] spells, int[] potions, long success) { int n = spells.length, m = potions.length; Arrays.sort(potions); int[] ans = new int[n]; for (int i = 0; i < n; ++i) { int left = 0, right = m - 1; while (left < right) { int mid = left + right >> 1; if ((long) spells[i] * potions[mid] > ...
LC.P2258[逃离火灾]
发表于2023-11-09|更新于2023-11-09|LeetCode|图•BFS•二分查找
LC.P2258[逃离火灾] 方法一:二分+BFS12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576class Solution { static int[][] dirs = new int[][]{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; int m, n; boolean flag; int[][] grid, fire, people; public int maximumMinutes(int[][] grid) { this.grid = grid; m = grid.length; n = grid[0].length; ...
LC.P768[最多能完成排序的块II]
发表于2023-11-08|更新于2023-11-08|LeetCode|栈•数组•贪心
LC.P768[最多能完成排序的块II] 方法一:栈+贪心123456789101112131415class Solution { public int maxChunksToSorted(int[] arr) { Deque<Integer> stack = new ArrayDeque<>(); for (int x : arr) { if (!stack.isEmpty() && x < stack.peek()) { int max = stack.poll(); while (!stack.isEmpty() && x < stack.peek()) stack.poll(); stack.push(max); } else { stack.push(x ...
LC.P2609[最长平衡子字符串]
发表于2023-11-08|更新于2023-11-08|LeetCode|字符串
LC.P2609[最长平衡子字符串] 方法一:枚举12345678910111213141516171819class Solution { public int findTheLongestBalancedSubstring(String s) { int ans = 0, n = s.length(), k = 0; for (int i = 0; i < n; ) { int cnt0 = 0, cnt1 = 0; while (k < n && s.charAt(k) == '0') { ++k; ++cnt0; } while (k < n && s.charAt(k) == '1') { ++k; ...
1…101112…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!
搜索
数据库加载中