classSolution: defareaOfMaxDiagonal(self, dimensions: List[List[int]]) -> int: x, y = 0, 0 for w, h in dimensions: if w**2 + h**2 > x**2 + y**2or w**2 + h**2 == x**2 + y**2and w * h > x * y: x, y = w, h return x * y
classSolution: def match(self, s, a): res = [] iflen(s) < len(a): return res mod, base =10**9 + 7, 31 key, h = 0, 1 m = len(a)
for i in range(m): key = (key * base + ord(a[i]) - ord('a')) % mod for i in range(m - 1): h = h * base % mod curr = 0 for i in range(len(s)): curr = (curr * base + ord(s[i]) - ord('a')) % mod if i >= m - 1: if curr == key: res.append(i - m + 1) curr = (curr - h * (ord(s[i - m + 1]) - ord('a')) % mod + mod) % mod return res
def beautifulIndices(self, s: str, a: str, b: str, k: int) -> List[int]: arr1 = self.match(s, a) arr2 = self.match(s, b) res = [] for v in arr1: x = bisect_left(arr2, v - k) y = bisect_right(arr2, v + k) if x != y: res.append(v) return res;
3007. 价值和小于等于 K 的最大数字
给你一个整数 k 和一个整数 x 。
令 s 为整数 num 的下标从 1 开始的二进制表示。我们说一个整数 num 的 价值 是满足 i % x == 0 且 s[i] 是 设置位 的 i 的数目。
classSolution: def match(self, s, a): res = [] iflen(s) < len(a): return res mod, base =10**9 + 7, 31 key, h = 0, 1 m = len(a)
for i in range(m): key = (key * base + ord(a[i]) - ord('a')) % mod for i in range(m - 1): h = h * base % mod curr = 0 for i in range(len(s)): curr = (curr * base + ord(s[i]) - ord('a')) % mod if i >= m - 1: if curr == key: res.append(i - m + 1) curr = (curr - h * (ord(s[i - m + 1]) - ord('a')) % mod + mod) % mod return res
def beautifulIndices(self, s: str, a: str, b: str, k: int) -> List[int]: arr1 = self.match(s, a) arr2 = self.match(s, b) res = [] for v in arr1: x = bisect_left(arr2, v - k) y = bisect_right(arr2, v + k) if x != y: res.append(v) return res