![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
weekly-contest
Leeli9316
这个作者很懒,什么都没留下…
展开
-
2022.07.31(LC_6133_分组的最大数量)
2022.07.31(LC_6133_分组的最大数量)原创 2022-07-31 15:02:34 · 171 阅读 · 1 评论 -
2022.07.31(LC_6132_使数组中所有元素都等于零)
2022.07.31(LC_6132_使数组中所有元素都等于零)原创 2022-07-31 14:57:53 · 245 阅读 · 0 评论 -
2022.07.24(LC_6126_设计食物评分系统)
2022.07.24(LC_6126_设计食物评分系统)原创 2022-07-24 16:51:10 · 207 阅读 · 0 评论 -
2022.07.24(LC_6125_相等行列对)
2022.07.17(LC_6125_相等行列对)原创 2022-07-24 16:06:33 · 141 阅读 · 0 评论 -
2022.07.24(LC_6124_第一个出现两次的字母)
2022.07.24(LC_6124_第一个出现两次的字母)原创 2022-07-24 15:23:37 · 104 阅读 · 0 评论 -
2022.07.17(LC_6121_裁剪数字后查询第 K 小的数字)
2022.07.17(LC_6121_裁剪数字后查询第K小的数字)原创 2022-07-17 15:34:57 · 91 阅读 · 0 评论 -
2022.07.17(LC_6164_数位和相等数对的最大和)
2022.07.17(LC_6164_数位和相等数对的最大和)原创 2022-07-17 15:30:56 · 112 阅读 · 0 评论 -
2022.07.17(LC_6120_数组能形成多少数对)
(LC_6120_数组能形成多少数对)原创 2022-07-17 15:03:36 · 102 阅读 · 0 评论 -
2022.07.10(LC_6113_无限集中的最小数字)
--既然集合是无限的,可以使用哈希表存放无限集没有的元素,移除无限集存在的元素。原创 2022-07-10 16:28:53 · 118 阅读 · 0 评论 -
2022.07.10(LC_6112_装满杯子需要的最短总时长)
方法二: //注:不管remainder是奇数还是偶数,都可以统一写成如下形式 //转换过程:首先(remainder - 1) / 2 + 1 + amount[2]转换后就是以下形式 //然后remainder / 2 + amount[2]先写成(amount[0] + amount[1] + amount[2]) / 2 //由于remainder是偶数,2amount[2]也是偶数,所以amount[0] + amount原创 2022-07-10 16:09:31 · 87 阅读 · 0 评论 -
2022.07.03(LC_6109_知道秘密的人数)
动态规划原创 2022-07-03 16:22:40 · 115 阅读 · 0 评论 -
2022.07.03(LC_6111_统计放置房子的方式数)
模拟原创 2022-07-03 15:41:31 · 54 阅读 · 0 评论 -
2022.07.03(LC_6108_解密消息)
模拟原创 2022-07-03 15:28:51 · 80 阅读 · 0 评论 -
2022.06.26(LC_6100_统计放置房子的方式数)
动态规划原创 2022-06-26 15:41:37 · 104 阅读 · 0 评论 -
2022.06.26(LC_6101_判断矩阵是否是一个 X 矩阵)
模拟原创 2022-06-26 15:35:41 · 123 阅读 · 0 评论 -
2022.06.19(LC_5218_个位数字为 K 的整数之和)
方法二:完全背包原创 2022-06-19 21:03:28 · 63 阅读 · 0 评论 -
2022.06.19(LC_5242_兼具大小写的最好英文字母)
将大写字母转化为小写:ch - 'A' + 'a'原创 2022-06-19 21:01:02 · 76 阅读 · 0 评论 -
2022.05.29(LC_6079_价格减免)
方法:模拟import java.text.DecimalFormat;class Solution { public String discountPrices(String sentence, int discount) { String[] str = sentence.split(" "); for (int i = 0; i < str.length; i++) { if (satisfy(str[i])) { ...原创 2022-05-29 15:58:02 · 49 阅读 · 0 评论 -
2022.05.29(LC_6078_重排字符形成目标字符串)
方法:计数class Solution { public int rearrangeCharacters(String s, String target) { Map<Character, Integer> tMap = new HashMap<>(); for (char ch : target.toCharArray()) { tMap.put(ch, tMap.getOrDefault(ch, 0) + ..原创 2022-05-29 15:18:23 · 56 阅读 · 0 评论 -
2022.05.22(LC_6076_表示一个折线图的最少线段数)
方法:计算斜率--注意先排序--注意溢出和精度损失问题class Solution { public int minimumLines(int[][] stockPrices) { int n = stockPrices.length; if (n == 1) return 0; if (n == 2) return 1; Arrays.sort(stockPrices, (a, b) -> a[0] - b[0..原创 2022-05-22 11:38:46 · 68 阅读 · 0 评论 -
2022.05.22(LC_6075_装满石头的背包的最大数量)
方法:贪心class Solution { public int maximumBags(int[] capacity, int[] rocks, int additionalRocks) { int n = capacity.length; List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) { if (..原创 2022-05-22 11:35:43 · 94 阅读 · 0 评论 -
2022.05.22(LC_6074_字母在字符串中的百分比)
方法:简单计算class Solution { public int percentageLetter(String s, char letter) { int count = 0; for (char ch : s.toCharArray()) { if (ch == letter) { count++; } } return count * 1..原创 2022-05-22 11:32:34 · 50 阅读 · 0 评论 -
2022.05.15(LC_6065_按位与结果大于零的最长组合)
方法:位运算class Solution { public int largestCombination(int[] candidates) { int ans = 0; for (int i = 0; i < 24; i++) { int count = 0; for (int candidate : candidates) { ans = Math.max(ans, count += (candidate & 1 << i) > ...原创 2022-05-15 18:56:09 · 112 阅读 · 0 评论 -
2022.05.15(LC_6064_不含特殊楼层的最大连续楼层数)
方法:分类讨论class Solution { public int maxConsecutive(int bottom, int top, int[] special) { int ans = 0; Arrays.sort(special); for (int i = 0; i < special.length; i++) { if (i == 0) { ans = Math....原创 2022-05-15 18:51:31 · 79 阅读 · 0 评论 -
2022.05.15(LC_5234_移除字母异位词后的结果数组)
方法:从前往后遍历class Solution { public List<String> removeAnagrams(String[] words) { List<String> ans = new ArrayList<>(List.of(words[0])); for (int i = 1; i < words.length; i++) { // if (!Arrays.equals(...原创 2022-05-15 18:44:28 · 59 阅读 · 0 评论 -
2022.05.08(LC_6056_字符串中最大的 3 位相同数字)
class Solution { public String largestGoodInteger(String num) { String ans = ""; for (int i = 0; i <= num.length() - 3; i++) { if (num.charAt(i) == num.charAt(i + 1) && num.charAt(i + 1) == num.charAt(i + 2)) {...原创 2022-05-08 17:43:10 · 227 阅读 · 0 评论 -
2022.05.01(LC_6048_必须拿起的最小连续卡牌数)
方法:哈希表class Solution { public int minimumCardPickup(int[] cards) { int ans = Integer.MAX_VALUE; Map<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < cards.length; i++) { if (map.conta...原创 2022-05-01 15:18:20 · 306 阅读 · 0 评论 -
2022.05.01(LC_6407_移除指定数字得到的最大结果)
方法:模拟class Solution { public String removeDigit(String number, char digit) { String ans = ""; for (int i = 0; i < number.length(); i++) { if (number.charAt(i) == digit) { StringBuilder sb = new Strin...原创 2022-05-01 15:13:35 · 172 阅读 · 0 评论 -
2022.04.17(LC_6071_完成所有任务需要的最少轮数)
方法:模拟class Solution {public int minimumRounds(int[] tasks) { Map<Integer, Integer> map = new HashMap<>(); for (int task : tasks) { map.put(task, map.getOrDefault(task, 0) + 1); } int ans = 0; ...原创 2022-04-17 16:43:32 · 276 阅读 · 0 评论 -
2022.04.17(LC_6070_计算字符串的数字和)
方法:递归模拟class Solution { public String digitSum(String s, int k) { if (s.length() <= k) return s; String temp = ""; for (int i = 0; i < s.length(); i += k) { int x = 0; for (int j = i; j < i...原创 2022-04-17 16:41:30 · 157 阅读 · 0 评论 -
2022.04.10(LC_6039_K 次增加后的最大乘积)
方法:优先队列(使用小顶堆)class Solution { public int maximumProduct(int[] nums, int k) { PriorityQueue<Integer> pq = new PriorityQueue<>(); int mod = 1000000007; for (int num : nums) { pq.offer(num); }...原创 2022-04-10 16:43:14 · 141 阅读 · 0 评论 -
2022.04.10(LC_6038_向表达式添加括号后的最小结果)
方法:模拟class Solution { public String minimizeResult(String expression) { int pos = expression.indexOf('+'); int n = expression.length(); int minVal = Integer.MAX_VALUE; int left = 0, right = 0; for (int i = ...原创 2022-04-10 16:41:17 · 159 阅读 · 0 评论 -
2022.04.10(LC_6037_按奇偶性交换后的最大数字)
方法:分组 + 排序class Solution { public int largestInteger(int num) { List<Integer> ji = new ArrayList<>(); List<Integer> ou = new ArrayList<>(); String number = "" + num; for (int i = 0; i < n...原创 2022-04-10 16:38:57 · 155 阅读 · 0 评论 -
2022.04.03(LC_6055_转化时间需要的最少操作数)
方法:模拟class Solution { public int cal(String time) { return Integer.parseInt(time.substring(0, 2)) * 60 + Integer.parseInt(time.substring(3, 5)); } public int convertTime(String current, String correct) { int dif = cal(corr...原创 2022-04-03 16:22:04 · 177 阅读 · 0 评论 -
2022.03.13(LC_6031_找出数组中的所有 K 近邻下标)
方法:暴力求解class Solution { public List<Integer> findKDistantIndices(int[] nums, int key, int k) { List<Integer> res = new ArrayList<>(); List<Integer> pos = new ArrayList<>(); int n = nums.length...原创 2022-03-13 17:20:07 · 57 阅读 · 0 评论 -
2022.03.06(LC_6018_根据描述创建二叉树)
/** * 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...原创 2022-03-06 16:29:04 · 246 阅读 · 0 评论 -
2022.03.06(LC_6017_向数组中追加 K 个整数)
class Solution { public long minimalKSum(int[] nums, int k) { //使用TreeSet排序并去重 Set<Integer> set = new TreeSet<>(); for (int num : nums) { set.add(num); } long res = 0; //从1开始...原创 2022-03-06 16:27:09 · 134 阅读 · 0 评论 -
2022.03.06(LC_6016_Excel 表中某个范围内的单元格)
class Solution { public List<String> cellsInRange(String s) { List<String> res = new ArrayList<>(); //总列数 int cols = s.charAt(3) - s.charAt(0) + 1; //起始和终止行数 int row1 = s.charAt(1) - '0';...原创 2022-03-06 16:24:16 · 41 阅读 · 0 评论