08 2022 档案

LeetCode338 比特位计数
摘要: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 阅读全文

posted @ 2022-08-24 16:56 solvit 阅读(21) 评论(0) 推荐(0)

[编程题]仓库配送(最短路, Dijskra)
摘要:[编程题]仓库配送 # 最短路径, Dijskra from cmath import cos from heapq import * from collections import defaultdict N, K, M = list(map(int, input().strip().split( 阅读全文

posted @ 2022-08-20 11:31 solvit 阅读(28) 评论(0) 推荐(0)

[编程题]项目经理(二分图)
摘要:[编程题]项目经理 参考, 模板 '''二分图, 匈牙利算法 最大匹配数: 最大匹配的匹配边的数目 最小点覆盖数: 选取最少的点, 使任意一条边至少有一个端点被选择 最大独立数: 选取最多的点, 使任意所选两点均不相连 最小路径覆盖数: 对于一个 DAG (有向无环图), 选取最少条路径, 使得每个 阅读全文

posted @ 2022-08-20 11:01 solvit 阅读(24) 评论(0) 推荐(0)

LeetCode54 螺旋矩阵
摘要: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, 阅读全文

posted @ 2022-08-15 11:06 solvit 阅读(19) 评论(0) 推荐(0)

LeetCode912 排序数组(手撕快排)
摘要:LeetCode912 排序数组 class Solution: def sortArray(self, nums: List[int]) -> List[int]: import random def partition(l: int, r: int) -> int: random_p = ran 阅读全文

posted @ 2022-08-15 10:10 solvit 阅读(45) 评论(0) 推荐(0)

LeetCode5 最长回文子串
摘要:LeetCode5 最长回文子串 Manacher 算法 # 最长回文子串, Manacher class Solution: def expend(self, s, left, right): while left >= 0 and right < len(s) and s[left] == s[ 阅读全文

posted @ 2022-08-13 17:01 solvit 阅读(20) 评论(0) 推荐(0)

LeetCode48 旋转图像
摘要:LeetCode48 旋转图像 先沿水平中线交换,再沿主对角线交换 class Solution: def rotate(self, matrix: List[List[int]]) -> None: """ Do not return anything, modify matrix in-plac 阅读全文

posted @ 2022-08-12 18:33 solvit 阅读(16) 评论(0) 推荐(0)

LeetCode1143 最长公共子序列
摘要:LeetCode1143 最长公共子序列 最长公共子串 class Solution: def longestCommonSubsequence(self, text1: str, text2: str) -> int: m, n = len(text1), len(text2) dp = [[0 阅读全文

posted @ 2022-08-11 16:16 solvit 阅读(25) 评论(0) 推荐(0)

LeetCode130 被围绕的区域(dfs)
摘要:LeetCode130 被围绕的区域 class Solution: def solve(self, board: List[List[str]]) -> None: """ Do not return anything, modify board in-place instead. """ m, 阅读全文

posted @ 2022-08-11 12:50 solvit 阅读(24) 评论(0) 推荐(0)

商汤科技2018校招 [编程题]解码
摘要:商汤科技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')): 阅读全文

posted @ 2022-08-09 22:24 solvit 阅读(31) 评论(0) 推荐(0)

LeetCode825 适龄的朋友
摘要:LeetCode825 适龄的朋友 二分求解,考虑重复情况 class Solution: def numFriendRequests(self, ages: List[int]) -> int: ans, n, idx = 0, len(ages), {} ages.sort() for i in 阅读全文

posted @ 2022-08-06 14:55 solvit 阅读(19) 评论(0) 推荐(0)

导航