classSolution: deffrequencySort(self, nums: List[int]) -> List[int]: mp = {} for n in nums: mp[n] = mp.get(n, 0) + 1 mp2 = {} for k, v in mp.items(): mp2.setdefault(v, []).append(k) res = [] for k in sorted(mp2.keys()): v = sorted(mp2[k], reverse=True) for n in v: for i in range(int(k)): res.append(n) return res
classSolution: defmaxWidthOfVerticalArea(self, points: List[List[int]]) -> int: lst = [] for p in points: lst.append(p[0]) lst.sort() x = 0 for i in range(1, len(lst)): x = max(x, lst[i] - lst[i - 1]) return x
classSolution: defcountSubstrings(self, s: str, t: str) -> int: trie = {} for i in range(len(t)): nxt = trie for c in t[i:]: nxt = nxt.setdefault(c, {}) nxt[''] = nxt.get('', 0) + 1 # print(trie) res = 0 for i in range(len(s)): res += self.cal(s, i, trie) return res defcal(self, s, idx, trie, diff=False): res = 0 if idx >= len(s): return res for c in trie: if c == '': continue next_trie = trie[c] if c == s[idx]: if diff: res += next_trie[''] res += self.cal(s, idx + 1, next_trie, diff) else: if diff: pass else: res += next_trie[''] res += self.cal(s, idx + 1, next_trie, True) return res