avatar
文章
590
标签
104
分类
17

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

byu_rself

LC.P1031[两个非重叠子数组的最大和]
发表于2023-04-26|更新于2023-04-27|LeetCode|数组•子数组•前缀和
LC.P1031[两个非重叠子数组的最大和] 方法一:前缀和+枚举1234567891011121314151617class Solution { public int maxSumTwoNoOverlap(int[] nums, int firstLen, int secondLen) { int n = nums.length; int[] s = new int[n +1]; for (int i = 0; i < n; ++i) s[i + 1] = s[i] + nums[i]; return Math.max(maxSubSum(s, firstLen, secondLen), maxSubSum(s, secondLen, firstLen)); } private int maxSubSum(int[] s, int firstLen, int secondLen) { int maxSumA = 0, ans = 0; ...
LC.P2418[按身高排序]
发表于2023-04-25|更新于2023-04-27|LeetCode|排序
LC.P2418[按身高排序] 方法一:排序123456789101112131415class Solution { public String[] sortPeople(String[] names, int[] heights) { int n = names.length; int[][] index = new int[n][2]; for (int i = 0; i < n; ++i) { index[i] = new int[]{heights[i], i}; } Arrays.sort(index, (a, b) -> b[0] - a[0]); String[] ans = new String[n]; for (int i = 0; i < n; ++i) { ans[i] = names[index[i][1]]; & ...
LC.P797[所有可能的路径]
发表于2023-04-24|更新于2023-04-27|LeetCode|DFS•图•回溯
LC.P797[所有可能的路径] 方法一:DFS1234567891011121314151617181920212223242526class Solution { int[][] graph; int n; List<List<Integer>> ans = new ArrayList<>(); List<Integer> path = new ArrayList<>(); public List<List<Integer>> allPathsSourceTarget(int[][] graph) { this.graph = graph; this.n = graph.length; path.add(0); dfs(0); return ans; } private void dfs(int i) { if (i == n - 1) ...
LC.P1163[按字典序排在最后的子串]
发表于2023-04-24|更新于2023-04-27|LeetCode|字符串•双指针•子串
LC.P1163[按字典序排在最后的子串] 方法一:双指针1234567891011121314151617181920class Solution { public String lastSubstring(String s) { int n = s.length(); int i = 0, j = 1, k = 0; while (j + k < n) { int d = s.charAt(i + k) - s.charAt(j + k); if (d == 0) { ++k; } else if (d < 0) { i = i + k + 1; k = 0; if (i >= j) j = i + 1; } else { ...
LC.P815[公交路线]
发表于2023-04-23|更新于2023-04-27|LeetCode|BFS
LC.P815[公交路线] 方法一:BFS12345678910111213141516171819202122232425262728293031323334353637class Solution { public int numBusesToDestination(int[][] routes, int source, int target) { if (source == target) return 0; int n = routes.length; Map<Integer, Set<Integer>> map = new HashMap<>(); // 某个车站可以进入的路线 Deque<Integer> queue = new ArrayDeque<>(); Map<Integer, Integer> stepMap = new HashMap<>(); for (int i = ...
LC.P1105[填充书架]
发表于2023-04-23|更新于2023-04-27|LeetCode|DFS•动态规划•记忆化搜索•递推
LC.P1105[填充书架] 方法一:动态规划(超时)12345678910111213141516171819202122class Solution { int[][] books; int shelfWidth; public int minHeightShelves(int[][] books, int shelfWidth) { this.books = books; this.shelfWidth = shelfWidth; return dfs(books.length - 1); } private int dfs(int i) { if (i < 0) return 0; int ans = Integer.MAX_VALUE, maxHeight = 0, width = 0; for (int j = i; j >= 0; --j) { width += books[j ...
LC.P1027[最长等差数列]
发表于2023-04-22|更新于2023-04-27|LeetCode|动态规划•数组
LC.P1027[最长等差数列] 方法一:动态规划定义$f[i][j]$表示以$nums[i]$结尾且公差为$j$的等差数列的最大长度。初始时$f[i][j] = 1$,表示每个元素自身都是一个长度为$1$的等差数列。 由于公差可能为负数,且最大差值为 500 ,因此,可以将统一将公差加上 500,这样公差的范围就变成了 $[0 , 1000]$ 如果初始时 $f[i][j] = 0$,那么我们需要在最后返回答案时加上 $1$。 1234567891011121314class Solution { public int longestArithSeqLength(int[] nums) { int n = nums.length, ans = 0; int[][] f = new int[n][1001]; // f[i][j]表示以nums[i]结尾且公差为j的等差数列的最大长度 for (int i = 0; i < n; ++i) { for (in ...
RPC学习笔记与项目实战
发表于2023-04-21|更新于2023-08-07|后端RPC|RPC
RPC学习笔记与项目实战Guide哥RPC学习笔记 RPC简介什么是RPC?RPC(Remote Procedure Call) 即远程过程调用,通过名字我们就能看出 RPC 关注的是远程调用而非本地调用。 为什么要 RPC ? 因为,两个不同的服务器上的服务提供的方法不在一个内存空间,所以,需要通过网络编程才能传递方法调用所需要的参数。并且,方法调用的结果也需要通过网络编程来接收。但是,如果我们自己手动网络编程来实现这个调用过程的话工作量是非常大的,因为,我们需要考虑底层传输方式(TCP 还是 UDP)、序列化方式等等方面。 RPC 能帮助我们做什么呢? 简单来说,通过 RPC 可以帮助我们调用远程计算机上某个服务的方法,这个过程就像调用本地方法一样简单。并且,我们不需要了解底层网络编程的具体细节。 举个例子:两个不同的服务 A、B 部署在两台不同的机器上,服务 A 如果想要调用服务 B 中的某个方法的话就可以通过 RPC 来做。 一言蔽之:RPC 的出现就是为了让你调用远程方法像调用本地方法一样简单。 RPC原理RPC的核心功能由以下5个部分实现: 客户端(服务消费端):调用远 ...
LC.P854[相似度为 K 的字符串]
发表于2023-04-21|更新于2023-04-21|LeetCode|字符串•BFS•回溯•剪枝
LC.P854[相似度为 K 的字符串] 方法一:BFS123456789101112131415161718192021222324252627282930313233343536373839404142434445class Solution { public int kSimilarity(String s1, String s2) { Deque<String> queue = new ArrayDeque<>(); Set<String> visited = new HashSet<>(); queue.offer(s1); visited.add(s1); int ans = 0; while (true) { for (int i = queue.size(); i > 0; --i) { String s = queue.poll(); ...
LC.P1723[完成所有工作的最短时间]
发表于2023-04-21|更新于2023-04-27|LeetCode|回溯•剪枝
LC.P1723[完成所有工作的最短时间] 方法一:回溯+剪枝(超时)1234567891011121314151617181920212223242526272829303132class Solution { int[] jobs; int n, k; int[] sum; int ans = Integer.MAX_VALUE; public int minimumTimeRequired(int[] jobs, int k) { this.jobs = jobs; this.k = k; this.n = jobs.length; sum = new int[n]; dfs(0, 0); return ans; } /** * @param cur 当前处理到的工作 * @param max 当前的最大工作时间 */ private void dfs(int cur, int max) ...
1…505152…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!
搜索
数据库加载中