摘要:LeetCode338 比特位计数 class Solution: def countBits(self, n: int) -> List[int]: def cnt(x: int) -> int: ones = 0 while x > 0: x = x & (x - 1) ones = ones
阅读全文
摘要:[编程题]仓库配送 # 最短路径, Dijskra from cmath import cos from heapq import * from collections import defaultdict N, K, M = list(map(int, input().strip().split(
阅读全文
摘要:[编程题]项目经理 参考, 模板 '''二分图, 匈牙利算法 最大匹配数: 最大匹配的匹配边的数目 最小点覆盖数: 选取最少的点, 使任意一条边至少有一个端点被选择 最大独立数: 选取最多的点, 使任意所选两点均不相连 最小路径覆盖数: 对于一个 DAG (有向无环图), 选取最少条路径, 使得每个
阅读全文
摘要:LeetCode54 螺旋矩阵 class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: m, n = len(matrix), len(matrix[0]) l, r, t, b, cnt, tar,
阅读全文
摘要:LeetCode912 排序数组 class Solution: def sortArray(self, nums: List[int]) -> List[int]: import random def partition(l: int, r: int) -> int: random_p = ran
阅读全文
摘要:LeetCode5 最长回文子串 Manacher 算法 # 最长回文子串, Manacher class Solution: def expend(self, s, left, right): while left >= 0 and right < len(s) and s[left] == s[
阅读全文
摘要:LeetCode48 旋转图像 先沿水平中线交换,再沿主对角线交换 class Solution: def rotate(self, matrix: List[List[int]]) -> None: """ Do not return anything, modify matrix in-plac
阅读全文
摘要:LeetCode1143 最长公共子序列 最长公共子串 class Solution: def longestCommonSubsequence(self, text1: str, text2: str) -> int: m, n = len(text1), len(text2) dp = [[0
阅读全文
摘要:LeetCode130 被围绕的区域 class Solution: def solve(self, board: List[List[str]]) -> None: """ Do not return anything, modify board in-place instead. """ m,
阅读全文
摘要:商汤科技2018校招 [编程题]解码 dp,注意'0'字符的处理 def solver(s, n): if n == 1: return 1 dp = [1] * n if s[1] != '0' and (s[0] == '1' or (s[0] == '2' and s[1] <= '6')):
阅读全文
摘要:LeetCode825 适龄的朋友 二分求解,考虑重复情况 class Solution: def numFriendRequests(self, ages: List[int]) -> int: ans, n, idx = 0, len(ages), {} ages.sort() for i in
阅读全文