用易语言做网站抢购软件,建设银行网站适用浏览器,如何建购物网站,网站建设yingkagou记录了初步解题思路 以及本地实现代码#xff1b;并不一定为最优 也希望大家能一起探讨 一起进步 目录 1/6 2274. 不含特殊楼层的最大连续楼层数1/7 3019. 按键变更的次数1/8 2264. 字符串中最大的 3 位相同数字1/9 3297. 统计重新排列后包含另一个字符串的子字符串数目 I1/10…记录了初步解题思路 以及本地实现代码并不一定为最优 也希望大家能一起探讨 一起进步 目录 1/6 2274. 不含特殊楼层的最大连续楼层数1/7 3019. 按键变更的次数1/8 2264. 字符串中最大的 3 位相同数字1/9 3297. 统计重新排列后包含另一个字符串的子字符串数目 I1/10 3298. 统计重新排列后包含另一个字符串的子字符串数目 II1/11 3270. 求出数字答案1/12 2275. 按位与结果大于零的最长组合 1/6 2274. 不含特殊楼层的最大连续楼层数 将bottom top加入数组中 遍历算出相邻最大值 def maxConsecutive(bottom, top, special)::type bottom: int:type top: int:type special: List[int]:rtype: intspecial.sort()l [bottom-1]special[top1]return max([l[i1]-l[i]-1 for i in range(len(l)-1)] ) 1/7 3019. 按键变更的次数 变成小写字母 从头遍历 寻找相邻不同的个数 def countKeyChanges(s)::type s: str:rtype: intss.lower()ans 0for i in range(1,len(s)):if s[i]!s[i-1]:ans1return ans 1/8 2264. 字符串中最大的 3 位相同数字 遍历 判断是否存在连续3个相同数字 def largestGoodInteger(num)::type num: str:rtype: strvfor i in range(len(num)-2):if num[i]num[i1]num[i2]:if num[i]v:vnum[i]return if v else v*3 1/9 3297. 统计重新排列后包含另一个字符串的子字符串数目 I 满足条件的x 即x内需要包含word2所有字符 对于每个子字符串左侧端点l 找到它满足条件最短时的右端点r 更右侧的所有必定都满足 可以有n-r1个子字符串 滑动窗口记录l,r diff记录满足word2每个字符还差几个 cnt记录不满足个数的字符个数 def validSubstringCount(word1, word2)::type word1: str:type word2: str:rtype: intnlen(word1)diff[0]*26for c in word2:diff[ord(c)-ord(a)]-1ans 0global cntcnt sum(1 for c in diff if c0)def update(c,add):global cntdiff[c]addif add1 and diff[c]0:cnt-1elif add-1 and diff[c]-1:cnt1l,r0,0while llen(word1):while rlen(word1) and cnt0:update(ord(word1[r])-ord(a),1)r1 if cnt0:ansn-r1update(ord(word1[l])-ord(a), -1)l1 return ans 1/10 3298. 统计重新排列后包含另一个字符串的子字符串数目 II 满足条件的x 即x内需要包含word2所有字符 对于每个子字符串左侧端点l 找到它满足条件最短时的右端点r 更右侧的所有必定都满足 可以有n-r1个子字符串 滑动窗口记录l,r diff记录满足word2每个字符还差几个 cnt记录不满足个数的字符个数 def validSubstringCount(word1, word2)::type word1: str:type word2: str:rtype: intnlen(word1)diff[0]*26for c in word2:diff[ord(c)-ord(a)]-1ans 0global cntcnt sum(1 for c in diff if c0)def update(c,add):global cntdiff[c]addif add1 and diff[c]0:cnt-1elif add-1 and diff[c]-1:cnt1l,r0,0while llen(word1):while rlen(word1) and cnt0:update(ord(word1[r])-ord(a),1)r1 if cnt0:ansn-r1update(ord(word1[l])-ord(a), -1)l1 return ans 1/11 3270. 求出数字答案 依次求最小值 def generateKey(num1, num2, num3)::type num1: int:type num2: int:type num3: int:rtype: intans 0for i in range(4):ansmin(num1%10,num2%10,num3%10)*(10**i)num1//10num2//10num3//10return ans 1/12 2275. 按位与结果大于零的最长组合 计算每一位为1的数个数 这些数相与必定大于0 求个数最大值即可 def largestCombination(candidates)::type candidates: List[int]:rtype: intdef find(i):ans 0for num in candidates:if num(1i):ans1return ansans 0for i in range(24):ans max(ans,find(i))return ans