一些题目记录

一些题目

Part1

https://zhuanlan.zhihu.com/p/32626732052

实现 NMS,七八次,很高频;
实现 MultiHeadSelfAttention,大概 三四次;
用 Numpy 或者 List 实现MLP 的前向和反向,4次;
Leetcode 岛屿数量,大概得五六次;
Leetcode 反转链表以及衍生的,3次;
Leetcode 数组中第K大的数,2次;
Leetcode 编辑距离,最长递增子序列、买卖股票等等,其他的记不清了;

Part2

1.环形数组的滑动窗口问题
数组由不同颜色的球组成,求包含全部颜色的数组最短长度
2.m个完全相同的球放到n个完全相同的盘子中,问有几种不同的方法(区分盘子可为空or不可为空)

Part3

【力扣中几个回溯题目】https://leetcode.cn/problems/ji-qi-ren-de-yun-dong-fan-wei-lcof/solutions/1448376/by-da-fei-de-tian-kong-dhms/

Part4

面试笔记:https://zhuanlan.zhihu.com/p/1902504372501480468

Part5

二维矩阵中最长递增路径,可以上下左右4个方向移动

class solution:
    
    def longestIncreasingPath(self, matrix):
        if not matrix or not matrix[0]:
            return 0
        m, n = len(matrix), len(matrix[0])
        dp = [[0] * n for _ in range(m)]
        max_len = 0
    
        for i in range(m):
            for j in range(n):
                current_len = self.dfs(dp, i, j, m, n)
                if current_len > max_len:
                    max_len = current_len
        return max_len

    def dfs(self, dp, i, j, m, n):
        if dp[i][j] != 0:
            return dp[i][j]
        max_path = 1
        directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
        for dx, dy in directions:
            x, y = i + dx, j + dy
            if 0 <= x < m and 0 <= y < n and matrix[x][y] > matrix[i][j]:
                max_path = max(max_path, 1 + self.dfs(dp, x, y, m, n))
        dp[i][j] = max_path
        return max_path

测试code

# 示例测试
matrix = [
    [9, 9, 4, 1],
    [11, 9, 8, 1],
    [12, 1, 1, 1]
]
solu = solution()
print(solu.longestIncreasingPath(matrix))  # 输出:6
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值