![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode周赛
文章平均质量分 59
莱安纳德
这个作者很懒,什么都没留下…
展开
-
Leetcode Weekly Contest 277(二进制枚举)
吐槽一下本次周赛,前三题都是简单的模拟题,完全拼手速。题目链接: Leetcode Weekly Contest 2771、2148. Count Elements With Strictly Smaller and Greater Elements难度:Easy代码:class Solution {public: int countElements(vector<int>& nums) { sort(nums.begin(),nums.end());原创 2022-01-23 16:12:43 · 472 阅读 · 0 评论 -
Leetcode Weekly Contest 276(贪心、DFS、动态规划)
题目链接: Leetcode Weekly Contest 2761、2133. Check if Every Row and Column Contains All Numbers难度:Easy思路模拟代码:class Solution { public String[] divideString(String s, int k, char fill) { int size=s.length()%k==0?s.length()/k:s.length()/k+1;原创 2022-01-18 20:05:45 · 267 阅读 · 0 评论 -
Leetcode Weekly Contest 275(暴力、滑动窗口、位掩码、贪心)
题目链接: Leetcode Weekly Contest 2751、2133. Check if Every Row and Column Contains All Numbers难度:Easy思路暴力求解。代码:class Solution { public boolean checkValid(int[][] matrix) { int n=matrix.length; for(int i=0;i<matrix.length;i++){原创 2022-01-11 21:10:58 · 285 阅读 · 0 评论 -
Leetcode Weekly Contest 272(双指针、贪心、二分查找)
题目链接: Leetcode Weekly Contest 2721、2108. Find First Palindromic String in the Array难度:Easy代码:class Solution { public String firstPalindrome(String[] words) { for(String s:words){ int l=0,r=s.length()-1; boolean flag=原创 2021-12-19 17:07:54 · 133 阅读 · 0 评论 -
Leetcode Weekly Contest 271(贪心+前缀和)
题目链接: Leetcode Weekly Contest 2711、2103. Rings and Rods难度:Easy代码:class Solution { public int countPoints(String rings) { int[][] colorCount=new int[10][3]; char[] s=rings.toCharArray(); for(int i=0;i<s.length/2;i++){原创 2021-12-12 16:06:34 · 219 阅读 · 0 评论 -
Leetcode Weekly Contest 267(链表、并查集)
题目链接: Leetcode Weekly Contest 2671、2073. Time Needed to Buy Tickets难度:Easy代码:class Solution { public int timeRequiredToBuy(int[] tickets, int k) { int res=0; int n=tickets.length; while(tickets[k]>1){ for(int原创 2021-12-09 10:38:34 · 224 阅读 · 0 评论 -
Leetcode Weekly Contest 269(前缀和、并查集)
题目链接: Leetcode Weekly Contest 2691、2089. Find Target Indices After Sorting Array难度:Easy代码:class Solution { public List<Integer> targetIndices(int[] nums, int target) { List<Integer> res=new ArrayList<>(); Arrays.so原创 2021-12-06 17:10:57 · 213 阅读 · 0 评论 -
Leetcode Weekly Contest 268(二分、贪心、进制转换)
题目链接: Leetcode Weekly Contest 2681、2078. Two Furthest Houses With Different Colors难度:Easy双指针,从左往右和从右往左各扫描一遍。代码:class Solution { public int maxDistance(int[] colors) { int l=0,r=colors.length-1; int res=0; while(l<r){原创 2021-11-27 09:52:55 · 190 阅读 · 0 评论 -
Leetcode Weekly Contest 266(数学、二分)
题目链接: Leetcode Weekly Contest 2651、难度:Easy代码:class Solution { public int smallestEqual(int[] nums) { for(int i=0;i<nums.length;i++){ if(i%10==nums[i]){ return i; } } return -1;原创 2021-11-05 19:37:41 · 107 阅读 · 0 评论 -
Leetcode Weekly Contest 264(字符串、DFS)
题目链接: Leetcode Weekly Contest 2641、2047. Number of Valid Words in a Sentence难度:Easy代码:class Solution { public int countValidWords(String sentence) { int j=0; while(j<sentence.length()&&sentence.charAt(j)==' '){原创 2021-10-24 22:26:53 · 1519 阅读 · 0 评论 -
Leetcode Weekly Contest 262(贪心、二分、折半查找)
题目链接: Leetcode Weekly Contest 2621、2032. Two Out of Three难度:Easy代码:class Solution { public List<Integer> twoOutOfThree(int[] nums1, int[] nums2, int[] nums3) { int[] count1=new int[101]; int[] count2=new int[101]; int[原创 2021-10-21 18:52:37 · 127 阅读 · 0 评论 -
Leetcode Weekly Contest 263(状态压缩、字符串)
题目链接: Leetcode Weekly Contest 2631、2042. Check if Numbers Are Ascending in a Sentence难度:Easy代码:class Solution { public boolean areNumbersAscending(String s) { String[] arr=s.split(" "); int prev=-1; for(String str:arr){原创 2021-10-19 15:22:30 · 88 阅读 · 0 评论 -
Leetcode Weekly Contest 261(数学推理、贪心)
题目链接: Leetcode Weekly Contest 2611、2027. Minimum Moves to Convert String难度:Easy代码:class Solution { public int minimumMoves(String s) { char[] a=s.toCharArray(); int res=0; for(int i=0;i<a.length;){ if(a[i]=='X原创 2021-10-05 16:45:05 · 87 阅读 · 0 评论 -
Leetcode Weekly Contest 260(前缀和、模拟、DP)
题目链接: Leetcode Weekly Contest 2601、2016. Maximum Difference Between Increasing Elements难度:Easy代码:class Solution { public int maximumDifference(int[] nums) { int n=nums.length; int min=nums[0]; int res=-1; for(int i=1原创 2021-09-28 20:57:54 · 76 阅读 · 0 评论 -
Leetcode Weekly Contest 259(数组、哈希)
题目链接: Leetcode Weekly Contest 2591、1995. Count Special Quadruplets难度:Easy思路:暴力。代码:class Solution { public int countQuadruplets(int[] nums) { int n=nums.length; int res=0; for(int i=0;i<n;i++){ for(int j=i+1;原创 2021-09-20 08:56:46 · 87 阅读 · 0 评论 -
Leetcode Weekly Contest 258(字符串、状态压缩)
题目链接: Leetcode Weekly Contest 2581、2000. Reverse Prefix of Word难度:Easy思路:模拟即可。代码:class Solution { public String reversePrefix(String word, char ch) { char[] s=word.toCharArray(); int index=-1; for(int i=0;i<s.length;i++原创 2021-09-12 17:28:55 · 100 阅读 · 0 评论 -
Leetcode Weekly Contest 257(暴力、排序、动态递归)
题目链接: Leetcode Weekly Contest 2571、1995. Count Special Quadruplets难度:Easy思路:暴力。代码:class Solution { public int countQuadruplets(int[] nums) { int n=nums.length; int res=0; for(int i=0;i<n;i++){ for(int j=i+1;原创 2021-09-12 17:27:28 · 99 阅读 · 0 评论 -
Leetcode Weekly Contest 256(滑动窗口、排序、状态压缩、动态规划)
题目链接: Leetcode Weekly Contest 2561、1984. Minimum Difference Between Highest and Lowest of K Scores难度:Easy思路:对数组从小到大排序,然后用长度为k的滑动窗口进行求解。代码:class Solution { public int minimumDifference(int[] nums, int k) { if(k==1){ return 0;原创 2021-09-01 14:39:27 · 94 阅读 · 0 评论 -
Leetcode Weekly Contest 255(回溯、剪枝)
题目链接: Leetcode Weekly Contest 255写在前面:本次周赛做出第一题和第二题。速度太慢,目测要掉分了。1、1979. Find Greatest Common Divisor of Array难度:Easy题意求数组中最大值和最小值的最大公约数。代码:class Solution { public int findGCD(int[] nums) { Arrays.sort(nums); int min=nums[0];原创 2021-08-24 17:16:10 · 72 阅读 · 0 评论 -
Leetcode Weekly Contest 254(快速幂、二分、BFS)
题目链接: Leetcode Weekly Contest 254写在前面:本次周赛做出第一题和第二题。1、1967. Number of Strings That Appear as Substrings in Word难度:Easy题意详见题目。代码:class Solution { public int numOfStrings(String[] patterns, String word) { int res=0; for(String s:p原创 2021-08-15 16:59:31 · 80 阅读 · 0 评论 -
Leetcode Weekly Contest 253(字符串、贪心、二分)
题目链接: Leetcode Weekly Contest 253写在前面:本次周赛做出第一题和第二题。1、1961. Check If String Is a Prefix of Array难度:Easy代码:class Solution { public boolean isPrefixString(String s, String[] words) { char[] arr=s.toCharArray(); StringBuilder sb=new原创 2021-08-08 21:05:57 · 91 阅读 · 0 评论 -
Leetcode Weekly Contest 252(贪心、动态规划、数学)
题目链接: Leetcode Weekly Contest 252写在前面:本次周赛做出第一题和第三题。1、1952. Three Divisors难度:Easy题目大意:判断一个正整数是否刚好有3个因子。思路:n的范围较小,统计其因子的数量即可。class Solution { public boolean isThree(int n) { int count=0; for(int i=1;i<=n;i++){ if(原创 2021-08-04 16:16:44 · 72 阅读 · 0 评论 -
Leetcode Weekly Contest 251(回溯、贪心)
题目链接: Leetcode Weekly Contest 251写在前面:本次周赛没有打,在比赛后进行模拟。做出了前两道。1、1945. Sum of Digits of String After Convert难度:Easy题目大意:将字符串按照规则转化成数字,再将数字各个位上的数相加求和。思路:按题意模拟即可。class Solution { public int getLucky(String s, int k) { char[] arr=s.toCharA原创 2021-08-04 16:15:11 · 80 阅读 · 0 评论 -
Leetcode Weekly Contest 250(前三题)
题目链接: Leetcode Weekly Contest 250写在前面:本次周赛没有参加,在赛后进行模拟的,做出了前两道。1、1935. Maximum Number of Words You Can Type难度:Easy题目大意:详见题意。思路:按照题意模拟即可。class Solution { public int canBeTypedWords(String text, String brokenLetters) { String[] arr=text.原创 2021-07-27 16:43:25 · 69 阅读 · 0 评论 -
Leetcode Weekly Contest 249(前两题)
题目链接: Leetcode Weekly Contest 249写在前面:本次周赛做出了前两题,头一次碰到一场周赛两道hard题。1、1929. Concatenation of Array难度:Easy题目大意:详见题意。思路:按照题意模拟即可。class Solution { public int[] getConcatenation(int[] nums) { int n=nums.length; int[] res=new int[2*n]原创 2021-07-12 15:38:36 · 83 阅读 · 0 评论 -
Leetcode Weekly Contest 248(前三题)
题目链接: Leetcode Weekly Contest 248写在前面:本次周赛手速场,前三题不难,虽然做的磕磕碰碰都做出来了,第四题难度比较大不会做。1、1920. Build Array from Permutation难度:Easy题目大意:详见题意。思路:按照题意模拟即可。class Solution { public int[] buildArray(int[] nums) { int n=nums.length; int[] ans=原创 2021-07-04 15:44:31 · 146 阅读 · 0 评论 -
Leetcode Weekly Contest 247(前三题)
题目链接: Leetcode Weekly Contest 247写在前面:本次周赛做出了第1题。1、1913. Maximum Product Difference Between Two Pairs难度:Easy题目大意:详见题意。思路:找出最大的两个数和最小的两个数,排序即可。代码class Solution { public int maxProductDifference(int[] nums) { int n=nums.length;原创 2021-06-30 10:10:47 · 71 阅读 · 0 评论 -
Leetcode Weekly Contest 246(详细解析)
题目链接: Leetcode Weekly Contest 246写在前面:本次周赛没有参加,在赛后进行了模拟。1、1903. Largest Odd Number in String难度:Easy题目大意:给出一个字符串,该字符串由数字组成,返回字串所能表示的最大奇数。思路:找到最后一位奇数所在的位置即可。代码class Solution { public String largestOddNumber(String num) { int n=num.lengt原创 2021-06-30 09:39:25 · 95 阅读 · 0 评论 -
Leetcode Weekly Contest 245(前3题)
题目链接: Leetcode Weekly Contest 245写在前面:本次周赛做出了第1题和第3题,端午假期也不能忘了打周赛鸭。1、1897. Redistribute Characters to Make All Strings Equal难度:Easy题目大意:给出一个字符串数组,每次操作可以将一个字符串中的一个字符移动到数组中莹莹字符串中的任意位置。判断能否将数组中的每个字符串变得都一样,操作次数不限。思路:因为操作次数不限,统计整个数组中各个字符的个数,然后判断能否平分都各个字原创 2021-06-13 19:01:43 · 74 阅读 · 0 评论 -
Leetcode Weekly Contest 244(详细解析)
题目链接: Leetcode Weekly Contest 244写在前面:本次周赛做出了前两题。1、1886. Determine Whether Matrix Can Be Obtained By Rotation难度:Easy题目大意:判断能否将一个二维方阵经过若干次顺时针旋转90度后变成另外一个矩阵。思路:找到方阵顺时针旋转90度后与原来方阵的关系即可。代码class Solution { public boolean findRotation(int[][] mat,原创 2021-06-09 10:32:22 · 176 阅读 · 0 评论 -
Leetcode Weekly Contest 243(详细解析)
题目链接: Leetcode Weekly Contest 243写在前面:本次周赛做出了前两题。1、1880. Check if Word Equals Summation of Two Words难度:Easy题目大意:将字符串按照题意规则转化成相应的值。思路:模拟即可 。代码class Solution { public boolean isSumEqual(String firstWord, String secondWord, String targetWord) {原创 2021-06-01 20:59:05 · 122 阅读 · 0 评论 -
Leetcode Weekly Contest 242
题目链接: Leetcode Weekly Contest 242写在前面:本次周赛做出了第一题。1、1869. Longer Contiguous Segments of Ones than Zeros难度:Easy题目大意:详见题意。思路:模拟即可,统计字符串中连续0和连续1的最长长度,然后比较即可。代码class Solution { public boolean checkZeroOnes(String s) { char[] arr=s.toCharAr原创 2021-05-26 13:59:53 · 120 阅读 · 0 评论 -
Leetcode Weekly Contest 241(详细解析)
题目链接: Leetcode Weekly Contest 241写在前面:本次周赛惨遭零封。1、1863. Sum of All Subset XOR Totals难度:Easy题目大意:详见题意。思路:参考高赞回答,穷举数组所有的子序列,用位运算来提高速度。代码class Solution { //参考https://leetcode.com/contest/weekly-contest-241/problems/sum-of-all-subset-xor-totals/原创 2021-05-19 16:53:56 · 85 阅读 · 0 评论 -
Leetcode Weekly Contest 239(详细解析)
题目链接: Leetcode Weekly Contest 239写在前面:本次周赛只做出了第一道。1、1848. Minimum Distance to the Target Element难度:Easy题目大意:详见题意。思路:根据题意模拟即可。代码class Solution { public int getMinDistance(int[] nums, int target, int start) { int res=Integer.MAX_VALUE;原创 2021-05-13 11:39:49 · 84 阅读 · 0 评论 -
Leetcode Weekly Contest 240(详细解析)
题目链接: Leetcode Weekly Contest 240写在前面:本次周赛做出了前两道。1、1854. Maximum Population Year难度:Easy题目大意:给出若干个人的出身年份与死亡年份,求人口最多那一年的人数。思路:思路1:暴力求解思路2:参考高赞回答,线性扫描,使用前缀和来进行求解。代码思路1代码;class Solution { public int maximumPopulation(int[][] logs) { i原创 2021-05-11 11:28:49 · 73 阅读 · 0 评论 -
Leetcode Weekly Contest 238(详细解析)
题目链接: Leetcode Weekly Contest 238写在前面:本次只做出了第一道,第三道一直到比赛结束也没有做对。1、1837. Sum of Digits in Base K难度:Easy题目大意:将十进制数n转成k进制,然后返回k进制数每一位数字相加之和。思路:按题意模拟即可。代码class Solution { public int sumBase(int n, int k) { int res=0; while(n>0原创 2021-04-27 12:05:22 · 77 阅读 · 0 评论 -
Leetcode Weekly Contest 237(详细解析)
题目链接: Leetcode Weekly Contest 237写在前面:本次周赛难度不大,做出了前两道,后两道道没有想出来,第三道大概的思路有,但是没有写出来,第四道爱猜才会赢,考了一个位运算的数学性质。1、1832. Check if the Sentence Is Pangram难度:Easy题目大意:字符串中只含有小写字母,判断字符串是否含有所有的小写字母。思路:统计每个字符的数量,然后判断即可。代码class Solution { public boolean ch原创 2021-04-19 14:31:03 · 62 阅读 · 0 评论 -
Leetcode Weekly Contest 236(前3题)
题目链接: Leetcode Weekly Contest 236写在前面:本次周赛做出了前两道,后两道道没有想出来。1、1822. Sign of the Product of an Array难度:Easy题目大意:详见题目思路:签到题,按题意模拟即可。代码class Solution { public int arraySign(int[] nums) { int product=1; for(int n:nums){原创 2021-04-12 11:35:38 · 69 阅读 · 0 评论 -
Leetcode Weekly Contest 235(详细解析)
题目链接: Leetcode Weekly Contest 235写在前面:本次周赛难度不大,拼手速,做出了前三道,第四道没有想出来,属于数学题。1、1816. Truncate Sentence难度:Easy题目大意:字符串中各个单词用空格分隔,返回前k个单词。思路:统计空格的个数,注意最后一个单词后面没有空格。代码class Solution { public String truncateSentence(String s, int k) { String原创 2021-04-05 20:21:29 · 71 阅读 · 0 评论 -
Leetcode Weekly Contest 234(详细解析)
题目链接: Leetcode Weekly Contest 234写在前面:本次周赛难度不大,但只做出了前两题,第三题在比赛结束后做出来了,手速还需提高。1、1805. Number of Different Integers in a String难度:Easy题目大意:将字符串中的字母有空格代替,如何以空格作为间隔将字符串中的数字分隔开,求字符串中有多少个不同的数值。012和12表示的数值相同。比较无聊的一道题,没那么容易做,磨了快半小时,写的代码比较丑。思路:按照题意一步步模拟。代原创 2021-03-30 20:53:26 · 67 阅读 · 0 评论