链接: 6319. 奇偶位数
按题意模拟即可。
class Solution:def evenOddBit(self, n: int) -> List[int]:e = o = 0for i in range(11):if (n>>i) & 1:if i&1:o += 1else:e += 1return [e,o]
链接: 6322. 检查骑士巡视方案
class Solution:def checkValidGrid(self, grid: List[List[int]]) -> bool:n = len(grid)a = []for i,row in enumerate(grid):for j,v in enumerate(row):a.append((v,i,j))a.sort()if a[0] != (0,0,0):return Falsedef ok(x,y,j,k):if abs(x-j) == 1 and abs(y-k) == 2:return Trueif abs(x-j) == 2 and abs(y-k) == 1:return Truereturn Falsefor (_,x,y),(_,j,k) in pairwise(a):if not ok(x,y,j,k):return Falsereturn True
链接: 6352. 美丽子集的数目
class Solution:def beautifulSubsets(self, nums: List[int], k: int) -> int:nums.sort()n = len(nums)ans = 0s = Counter()def dfs(i):if i == n:nonlocal ansans += 1return v = nums[i]if s[v-k] == 0 and s[v+k] == 0:s[v] += 1dfs(i+1)s[v] -= 1dfs(i+1)dfs(0)return ans - 1
链接: 6321. 执行操作后的最大 MEX
class Solution:def findSmallestInteger(self, nums: List[int], value: int) -> int:n = len(nums)cnt = Counter()for v in nums:cnt[v%value] += 1ans = 0 while cnt[ans%value]> 0:cnt[ans%value]-=1ans += 1return ans