【LeetCode】406. Queue Reconstruction by Height 解题记录
问题描述
You are given an array of people, people, which are the attributes of some people in a queue (not necessarily in order). Each people[i] = [hi, ki] represents the ith person of height hi with exactly ki other people in front who have a height greater than or equal to hi.
Reconstruct and return the queue that is represented by the input array people. The returned queue should be formatted as an array queue, where queue[j] = [hj, kj] is the attributes of the jth person in the queue (queue[0] ...
【LeetCode】763. Partition Labels 解题记录
问题描述
A string S of lowercase English letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a list of integers representing the size of these parts.
测试样例
123456Input: S = "ababcbacadefegdehijhklij"Output: [9,7,8]Explanation:The partition is "ababcbaca", "defegde", "hijhklij".This is a partition so that each letter appears in at most one part.A partition like "abab ...
【LeetCode】122. Best Time to Buy and Sell Stock II 解题记录
问题描述
You are given an array prices where prices[i] is the price of a given stock on the ith day.
Find the maximum profit you can achieve. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times).
Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).
测试样例
1234Input: prices = [7,1,5,3,6,4]Output: 7Explanation: Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5- ...
【LeetCode】452. Minimum Number of Arrows to Burst Balloons 解题记录
问题描述
There are some spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it’s horizontal, y-coordinates don’t matter, and hence the x-coordinates of start and end of the diameter suffice. The start is always smaller than the end.
An arrow can be shot up exactly vertically from different points along the x-axis. A balloon with xstart and xend bursts by an arrow shot at x if xstart ≤ x ≤ xend. There ...
【LeetCode】833. Find And Replace in String 解题记录
问题描述
To some string S, we will perform some replacement operations that replace groups of letters with new ones (not necessarily the same size).
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
For example, if we have S = “abcd” and we have some replacement operation i = 2, x = “cd”, y = “ffff”, then ...
【LeetCode】605. Can Place Flowers 解题记录
问题描述
You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots.
Given an integer array flowerbed containing 0’s and 1’s, where 0 means empty and 1 means not empty, and an integer n, return if n new flowers can be planted in the flowerbed without violating the no-adjacent-flowers rule.
测试样例
12Input: flowerbed = [1,0,0,0,1], n = 1Output: true
12Input: flowerbed = [1,0,0,0,1], n = 2Output: false
说明
12341 <= flowerb ...
【LeetCode】135. Candy 解题记录
问题描述
There are n children standing in a line. Each child is assigned a rating value given in the integer array ratings.
You are giving candies to these children subjected to the following requirements:
Each child must have at least one candy.
Children with a higher rating get more candies than their neighbors.
Return the minimum number of candies you need to have to distribute the candies to the children.
测试样例
123Input: ratings = [1,0,2]Output: 5Explanation: You can allocate to the first, se ...
【LeetCode】435. Non-overlapping Intervals 解题记录
问题描述
Given an array of intervals intervals where intervals[i] = [starti, endi], return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.
测试样例
123Input: intervals = [[1,2],[2,3],[3,4],[1,3]]Output: 1Explanation: [1,3] can be removed and the rest of the intervals are non-overlapping.
123Input: intervals = [[1,2],[1,2],[1,2]]Output: 2Explanation: You need to remove two [1,2] to make the rest of the intervals non-overlapping.
123Input: intervals ...
【LeetCode】455. Assign Cookies 解题记录
问题描述
Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie.
Each child i has a greed factor g[i], which is the minimum size of a cookie that the child will be content with; and each cookie j has a size s[j]. If s[j] >= g[i], we can assign the cookie j to the child i, and the child i will be content. Your goal is to maximize the number of your content children and output the maximum number.
测试样例
12345Input: g = [1,2,3 ...
Lecture 2: 有监督的多任务学习和迁移学习
多任务学习
问题陈述
符号说明
单任务学习
数据集: D={(x,y)k}\mathcal{D} = \left\{(x, y)_k \right\}D={(x,y)k}
目标: minθL(θ,D)\min_{\theta} \mathcal{L}(\theta, \mathcal{D})minθL(θ,D)
典型损失函数-负对数似然:L(θ,D)=−E(x,y)∼D[logfθ(y∣x)]\mathscr{L}(\theta, \mathscr{D})=-\mathbb{E}_{(x, y) \sim \mathscr{D}}\left[\log f_{\theta}(\mathbf{y} \mid \mathbf{x})\right]L(θ,D)=−E(x,y)∼D[logfθ(y∣x)]
任务
任务的形式化定义:Ti≜{pi(x),pi(y∣x),Li}\mathscr{T}_{i} \triangleq\left\{p_{i}(\mathbf{x}), p_{i}(\mathbf{y} \mid \mathbf{x}), \mathscr{L}_{ ...