首页 > 新浪8.18算法笔经
头像
在线求offer666
发布于 2021-08-24 14:29
+ 关注

新浪8.18算法笔经

1、选择题10道略过
2、算法题:
1)魔法森林,LeetCode 354. 俄罗斯套娃信封问题 未ac
    思路:将信封的宽度先排序,则题目转为最长上升子序列问题
class Solution(object):
    def maxEnvelopes(self, envelopes):
        """
        :type envelopes: List[List[int]]
        :rtype: int
        """
        # 先将信封按宽度排序
        envelopes.sort(key=lambda x:(x[0],-x[1]))
        # 将问题转换为最长上升子序列
        # dp[i]表示第i个信封可以装多少个信
        dp = [1]*len(envelopes)
        dp[0] = 1
        ans = 1
        for i in range(1,len(envelopes)):
            for j in range(i):
                if envelopes[i][1] > envelopes[j][1]:
                    dp[i] = max(dp[i],dp[j]+1)
                ans = max(ans,dp[i])
        # print(dp)
        # print(envelopes)
        return ans
2)LeetCode 283. 移动零 (全ac)
class Solution(object):
    def moveZeroes(self, nums):
        """
        :type nums: List[int]
        :rtype: None Do not return anything, modify nums in-place instead.
        """
        if len(nums)<=1:
            return nums
        p = 0
        while p<len(nums) and nums[p] != 0:
            p+=1
        if p == len(nums):
            return nums
        q = p+1
        while p<q and q<len(nums):
            if nums[q] != 0:
                nums[p],nums[q] = nums[q],nums[p]
                p+=1
            q+=1
        return nums

3、问答题
1)激活函数 
     i)常见激活函数及其导数  ii)为什么sigmoid和tanh会导致梯度消 iii)relu比sigmoid和tanh好在哪 relu本身有哪些局限如何改进
2)个性化推荐
     i)数据集负样本如何设计 ii)采用什么模型和算法提取用户和新闻之间的联系 iii)通过什么方式表征用户与新闻的关系



全部评论

(2) 回帖
加载中...
话题 回帖

相关热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

近期精华帖

热门推荐