Sirin Schariac

Thinking will not overcome fear but action will.

Leetcode 215 Kth Largest Element in an Array

大根堆

大根堆 除了快速排序、归并排序之外,一个比较常见的更加灵活的排序方式是堆排序。特别是在215. Kth Largest Element in an Array一题中,堆排和快速选择算法都是非常出色的解决方法。 那么堆排是如何实现的呢? 其核心思想是将数组看作一棵二叉树,保证二叉树的父节点大于其左右子树内的左右节点,从而构建起一个大根堆(如果是小于,那么就是小根堆)。对于节点idx如果其...

Leetcode 84. Largest Rectangle in Histogram

递增栈

84. Largest Rectangle in Histogram 原题 84. Largest Rectangle in Histogram 解答思路 本题的核心思路是采用递增栈来做,但为什么? 这是因为,在计算柱状图中的矩形面积时,核心思想是关注每个Bar所在最大矩阵的面积是多少。因为当前这个Bar_x的高度是已知的,那我们想知道的就是这个Bar_x所在矩形的...

Leetcode 739 Daily Temperatures

单调栈

739. Daily Temperatures 原题 739. Daily Temperatures 解答思路 这道题的思路比较简单,很容易看出来是个单调栈。但具体怎么构造和维护这个单调栈却需要多思考和注意细节。 一开始我对于本题的解答就复杂化了,另外用了type Record struct来存储气温、天数、下标等信息,还采取在栈内遍历的方式来更新天数,最后自然TL...

闭区间二分查找

闭区间二分查找模板

闭区间二分查找 原题 153. 寻找旋转排序数组中的最小值 - 力扣(LeetCode) 33. 搜索旋转排序数组 - 力扣(LeetCode) 闭区间二分查找模板 func binarySearch(nums[] int, target int) int { low, high := 0, len(nums)-1 for low < high { mid...

LeetCode 34:Find First and Last Position of Element in Sorted Array

二分查找

排序数组查找元素第一个和最后一个 原题 34. 在排序数组中查找元素的第一个和最后一个位置 - 力扣(LeetCode) 题目解析 这一题目是一个典型的二分查找,不过考察的细节更多,需要对于二分查找有一个比较深入的理解。 题目的核心问题:对于一个元素,找到其在数列中的开始和结束位置。这一问题可以转化为,找到第一个target和第一个大于target的元素。此时我们发现,传统...

Golang Sclices

append slices的细节

关于Golang中的slices append操作 在Leetcode回溯相关的题目中(e.g. 131. 分割回文串 - 力扣(LeetCode)),涉及到对于回溯过程中得到的多种方案的答案合并问题,采用的是ans = append(ans, append([]string(nil), splits...)),这就引出一个问题,为什么不直接采用ans = append(ans, spli...

UMich DL for CV

Generative Models-2

Generative Adversarial Networks Generative Models Review Autoregressive Models directly maximize likelihood of training data \(p_{\theta}(x)=\prod_{i=1}^N p_{\theta}(x_i|x_1,\dots,x_{i-1})\) Var...

UMich DL for CV

Generative Models-1

判别模型与生成模型 Component Supervised Learning Unsupervised Learning Data (x: data, y: label) (x: data) Goal learn a fun...

UMich DL for CV

Attention

Attention Machine Translation (seq2seq) Here $a_{ij}$ represents the weights of input sequence predicted by the attention. e.g., if the word ‘estamos’ = ‘eating’, then maybe $a_{23}=0.8\;a_{21...

UMich DL for CV

Recurrent Neural Networks

Recurrent Neural Networks Key idea RNNs have an “internal state” that is updated as a sequence is processed, the recurrence formula looks like $h_t = f_W(h_{t-1},x_t)$. Here $h_t$ is the state a...