算法
记录算法学习
CS-ZH
day day up!
展开
-
599. 两个列表的最小索引总和
方法一:哈希表 class Solution { public String[] findRestaurant(String[] list1, String[] list2) { Map<String, Integer> index = new HashMap<String, Integer>(); for (int i = 0; i < list1.length; i++) { index.put(list1[i原创 2022-03-14 10:16:49 · 83 阅读 · 0 评论 -
2049. 统计最高分的节点数目
class Solution { long maxScore = 0; // 记录最高分 int cnt = 0; // 最高分的节点数目,count的缩写 int n; // 节点数目 List<Integer>[] children; // 每个节点的子节点列表 public int countHighestScoreNodes(int[] parents) { n = parents.length; children原创 2022-03-11 10:19:32 · 308 阅读 · 0 评论 -
2055. 蜡烛之间的盘子
class Solution { public int[] platesBetweenCandles(String s, int[][] queries) { // 前缀和 int n = s.length(); int[] preSum = new int[n]; for (int i = 0, sum = 0; i < n; i++) { if (s.charAt(i) == '*') {原创 2022-03-09 14:19:39 · 152 阅读 · 0 评论 -
521. 最长特殊序列 Ⅰ
521. 最长特殊序列 Ⅰ class Solution { public int findLUSlength(String a, String b) { return !a.equals(b) ? Math.max(a.length(), b.length()) : -1; // 若两字符串相同,返回-1;若两字符串不相同,返回长字符串的长度。 } } ...原创 2022-03-07 17:11:07 · 45 阅读 · 0 评论 -
2100. 适合打劫银行的日子
2100. 适合打劫银行的日子 方法一:动态规划 class Solution { public List<Integer> goodDaysToRobBank(int[] security, int time) { int n = security.length; int[] left = new int[n]; int[] right = new int[n]; for (int i = 1; i < n; i+原创 2022-03-07 17:06:08 · 61 阅读 · 0 评论 -
504. 七进制数
504. 七进制数 方法一:倒推 + 迭代 class Solution { public String convertToBase7(int num) { if (num == 0) return "0"; boolean negative = num < 0; // 直接判断num是否小于0 num = Math.abs(num); StringBuffer digits = new原创 2022-03-07 17:00:44 · 61 阅读 · 0 评论 -
522. 最长特殊序列 II
522. 最长特殊序列 II 方法一:暴力解法 【通过】 public class Solution { public int findLUSlength(String[] strs) { HashMap < String, Integer > map = new HashMap < > (); for (String s: strs) { for (int i = 0; i < (1 << s.len原创 2022-03-05 17:04:38 · 204 阅读 · 0 评论