自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(77)
  • 收藏
  • 关注

原创 Linear regression by Bayesian and Frequentist

#Bayesian Method概率统计分频率学派(Frequentist)和贝叶斯学派(Bayesian),分别以极大似然估计(Maximum Likelihood Estimation)和贝叶斯后验估计方法(Bayesian Posterior)为各自特色。贝叶斯方法分为统计推断(inference)和预测(predict)两个阶段。#Inference...

2019-01-30 17:54:51 545

原创 数学公式编辑

∑i=1nai=0\sum_{i=1}^n a_i=0i=1∑n​ai​=0(1xx2⋯1yy21zz2) \begin{pmatrix} 1 & x & x^2 & \cdots \\ 1 & y & y^2 \\ 1 & z &a

2019-01-28 16:07:17 430

原创 LeetCode--91. Decode Ways

问题链接:https://leetcode.com/problems/decode-ways/这个问题在剑指Offer中也有类似问题,需要注意的是‘0’和类似以‘012’这类以‘0’开头的串是无法编码的。使用的是经典的DP算法思想,而分析方法是采用自顶向下的递归方法。状态转移方程:                                                       ...

2019-01-28 13:41:19 153

原创 LeetCode--140. Word Break II

问题链接:https://leetcode.com/problems/word-break-ii/这是紧接着Word Break I的问题,难度上更大,因为要记录所有切分结果所以动态规划的方法就不太奏效了,先复习一下这个问题的算法:dp[i]表示字串0-i是否存在一个切分使得切分后的各个部分都在字典中,状态转移方程为:                                    ...

2019-01-26 21:47:20 181

原创 LeetCode--128. Longest Consecutive Sequence

问题链接:https://leetcode.com/problems/longest-consecutive-sequence/数组中最长连续值子序列,时间复杂度要求O(n)。没有时间复杂度的要求该问题十分简单。先排序,再遍历一遍计数,时间复杂度为O(nlogn):class Solution { public int longestConsecutive(int[] num...

2019-01-26 12:50:11 115

原创 LeetCode--41. First Missing Positive

问题链接:https://leetcode.com/problems/first-missing-positive/问题要求在O(n)时间复杂度内完成,返回数组连续值序列中缺失的最小的正数,需要使用Bitmap这种数据结构来解决。不难理解,代码如下:class Solution { public int firstMissingPositive(int[] nums) { ...

2019-01-26 12:27:18 112

原创 LeetCode--45. Jump Game II

问题链接:https://leetcode.com/problems/jump-game-ii/这个问题是在https://blog.csdn.net/To_be_to_thought/article/details/84426854的Jump Game基础上深化而来,基本思路还是动态规划的思想。我的思路是:维护一个动态规划数组dp,dp[i]表示当前数组位置i经过至少dp[i]步才能到达...

2019-01-26 12:16:45 131

原创 LeetCode--56. Merge Intervals & 435. Non-overlapping Intervals & 57. Insert Interval

问题链接:https://leetcode.com/problems/merge-intervals/、https://leetcode.com/problems/non-overlapping-intervals/和https://leetcode.com/problems/insert-interval/第一问:求合并后的区间集合,应该是合并重叠区间,重叠区间的充要条件是前一个区间的右...

2019-01-21 21:40:45 157

原创 LeetCode--915. Partition Array into Disjoint Intervals

问题链接:https://leetcode.com/problems/partition-array-into-disjoint-intervals/这个问题也是做Virtual Contest时做到的,要在数组A中找一个位置i,使得左子数组max(A[:i])<=min(A[i+1:])(这里的i和i+1都取到),maxLeft[i]表示A[:i]中最大元素,minRight[i:]表...

2019-01-20 15:41:51 161

原创 LeetCode--978. Longest Turbulent Subarray

问题链接:https://leetcode.com/problems/longest-turbulent-subarray/最近本菜鸡在尝试参加LeetCode Contest,发现自己的水平在规定时间里也只能AC两个题,这么短的时间里做到bugfree还是蛮难的,路还很长呀。今天遇到这条很有趣的问题。要求最长波动子数组的长度,这个波动可以形象理解为子数组任意相邻三个元素先增大后减小或者先减小...

2019-01-20 15:12:20 215

原创 LeetCode--300. Longest Increasing Subsequence

问题链接:https://leetcode.com/problems/longest-increasing-subsequence/要求最长上升子序列,这是一个十分经典的问题!!!动态规划解法与https://blog.csdn.net/To_be_to_thought/article/details/86655842的Jump Game、Jump Game II十分类似,原因是动态规划的...

2019-01-18 17:09:14 121

原创 LeetCode--916. Word Subsets

问题链接:https://leetcode.com/problems/word-subsets/这个题目其实比LeetCode--392. Is Subsequence还简单,感觉很水,想不到什么实际应用场景。贴上我低效的代码:class Solution { public static HashSet<String> set; publ...

2019-01-18 17:03:45 162

原创 LeetCode--914. X of a Kind in a Deck of Cards

问题链接:https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards/能想到的就是求多个数的公约数(只会求两个数的),但我不会求呀,然后想的解法就比较暴力,就是先找到数字出现次数中的最小值min,然后从min到2开始搜索找到能够被所有出现次数记录整除的数字。代码如下:class Solution { public bo...

2019-01-18 16:59:10 205

原创 LeetCode--384. Shuffle an Array

问题链接:https://leetcode.com/problems/shuffle-an-array/实现shuffle(洗牌)和reset(复位)操作,一开始理解的permutation就是随即交换两个数即可,代码如下:class Solution { int a; int b; int[] arr; public Solution(int...

2019-01-18 11:40:53 130

原创 LeetCode--392. Is Subsequence & 792. Number of Matching Subsequences

问题链接:https://leetcode.com/problems/is-subsequence/和https://leetcode.com/problems/number-of-matching-subsequences/s是否为t的子序列,序列不要求字符相邻,而子串需要。这两道是姊妹题,问题二就是问题一里面follow-up的问题。问题一思路一:这也是我的思路,比较直接的双指针,代码...

2019-01-18 11:10:32 162

原创 LeetCode--354. Russian Doll Envelopes

问题链接:https://leetcode.com/problems/russian-doll-envelopes/俄罗斯套娃问题,因垂丝汀!!!,要求俄罗斯套娃能够达到的最多嵌套的层数。先要理解对于两个封套(数组a和数组b)怎样才能嵌套在一起:当a[0]<b[0] && a[1]<b[1]。那是不是要对原二维数组进行排序呢?答案是肯定的!排完序后呢?这个问题是...

2019-01-18 10:09:35 251

原创 LeetCode--380. Insert Delete GetRandom O(1) & 381. Insert Delete GetRandom O(1) - Duplicates allowed

问题链接:https://leetcode.com/problems/insert-delete-getrandom-o1/(Medium)和https://leetcode.com/problems/insert-delete-getrandom-o1-duplicates-allowed/(Hard)设计一个支持插入、删除和随机取值(所有操作的时间复杂度为O(1))的数据结构。随机取值只能...

2019-01-18 10:01:05 121

原创 LeetCode--279. Perfect Squares

问题链接:https://leetcode.com/problems/perfect-squares/十分有趣的一个问题,求出目标数的完全平方数和分解,使得和式的完全平方数数量最小。这个问题该从什么地方入手呢?这是一个目标和搜索问题,因此搜索范围的确定极其重要,搜索范围的最大值应该小于等于小于等于目标值的最大完全平方数,最小值为1,因此可以使用一个数组来存储这些完全平方数,然后进行递归搜索,注...

2019-01-13 22:48:58 123

原创 前缀树(Trie树、字典树)(三)

这一篇是关于三向Trie的数据结构设计,该数据结构克服了前两篇Trie实现出现大量空引用浪费内存的问题,但是算法更加复杂。树节点设计包括一个字符变量(表示该节点的字符),单词对象(可以为null)和三个指向树节点的引用指针,代码如下:private static class TernaryTrieNode<T>{ private T val; ...

2019-01-13 15:26:37 280

原创 LeetCode--274. H-Index & 275. H-Index II

问题连接:https://leetcode.com/problems/h-index/和https://leetcode.com/problems/h-index-ii/这两个问题属于一个问题,第二个的引用数数组已经排序,有对数时间复杂度要求。H-index的概念理解还是很挠头的。举个例子:0 3 5 5 6和0 1 3 5 6:到底是数组值(高被引文章的引用数)重要还是高被引篇数重要呢?...

2019-01-13 14:29:56 155

原创 LeetCode--263. Ugly Number & 264. Ugly Number II & 313. Super Ugly Number

问题链接:https://leetcode.com/problems/ugly-number/和https://leetcode.com/problems/ugly-number-ii/和https://leetcode.com/problems/super-ugly-number/关于丑陋数,问题比较简单,问题二和三也不难,但值得研究研究。问题一思路:比较直接没啥好说的,注意丑陋数为正数...

2019-01-13 13:37:36 171

原创 LeetCode--221. Maximal Square

问题链接:https://leetcode.com/problems/maximal-square/、要求在二值矩阵中寻找最大全1正方形的面积。思路一:一开始只能想到暴力搜索,代码如下class Solution { public int maximalSquare(char[][] matrix) { if(matrix==null || matrix.le...

2019-01-13 11:31:28 227

原创 LeetCode--216. Combination Sum III

题目链接:https://leetcode.com/problems/combination-sum-iii/该问题与Combination Sum、Combination Sum II都是同一种类型的问题,都是套路,还是沿用相同的模板,代码如下:class Solution { public static List<List<Integer>>...

2019-01-13 10:42:20 126

原创 前缀树(Trie树、字典树)(二)

上一篇https://blog.csdn.net/To_be_to_thought/article/details/86321842介绍了在字母表下Trie树的两种实现方式,如果不是字母表,而是一些具有层次关系、包含关系的对象呢,比如如下问题:测试数据如下:机器学习,线性模型,线性回归,最小二乘法,神经网络,神经元模型,激活函数,,多层网络,感知机,,,连接权,强化学习,有模...

2019-01-12 22:42:51 188

原创 前缀树(Trie树、字典树)(一)

字典树是一种是十分强大的高级数据结构,常用于字典和文件目录。首先是树节点的设计,我们是用一个数组(字母与数组索引的映射关系时常用的tricky操作)和值对象来表达一个树节点,而键对象是由沿着树的路径搜索字符拼接而成的,当某节点键对象为空时,表明当前路径组成的字符串不存在于字典中,不为空则存在。举个例子:假设字母表只有ABCD四个字母,依次插入ABAB、ABBAB、BADA、BCDA、AB、...

2019-01-11 22:33:52 254

原创 LeetCode--146. LRU Cache

问题链接:https://leetcode.com/problems/lru-cache/该问题可以具体参考算法设计这一篇,采用泛型编程完成,本题代码如下:class LRUCache { private HashMap<Integer,DLinkedListNode> hashmap; private int capacity; //缓...

2019-01-11 21:56:53 108

原创 LRU Cache(Least Recent Used缓存)

在有限内存空间中,抛弃距当前时间最远被使用(访问)的元素的缓存的数据结构,能够添加元素,读取元素。这个数据结构在操作系统中经常被使用到,见wikipedia链接https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)。使用一个双端链表和一个HashMap可以在O(1)时间、O(n)空间内...

2019-01-11 20:53:56 315 1

原创 LeetCode--190. Reverse Bits

题目链接:https://leetcode.com/problems/reverse-bits/将一个无符号整型数的二进制表达做对称变换,输出逆转后二进制表达对应的十进制思路:对于一个二进制表达的数,逐个取每一位上的数,然后将i位置上的1或者0转到32-i位置上,取末尾位上的数只要:tail=n&1代码如下:public class Solution { //...

2019-01-11 19:46:38 168

原创 LeetCode--303. Range Sum Query - Immutable

问题链接:https://leetcode.com/problems/range-sum-query-immutable/这个问题属于数据结构设计的问题,属于开放式问题。思路一:在查询时直接暴力计算,代码省略。思路二:哈希缓存,初始化复杂度O(n^2),查询复杂度O(1),代码如下:private Map<Pair<Integer, Integer>, Inte...

2019-01-10 21:09:06 199

原创 LeetCode--289. Game of Life

题目链接:https://leetcode.com/problems/game-of-life/这个问题就是生命游戏的简化版。思路一:非原地暴力算法比较容易想到,代码如下class Solution { public void gameOfLife(int[][] board) { int row=board.length,col=...

2019-01-10 20:50:16 135

原创 LeetCode--299. Bulls and Cows

题目链接:https://leetcode.com/problems/bulls-and-cows/问题读起来很费解,但也是水题类型。在同一位置相同数字字符则多一个Bull,而其他出现多次的只要进行计数比较取较小值。class Solution { public String getHint(String secret, String guess) { ...

2019-01-10 20:25:23 114

原创 LeetCode--72. Edit Distance

题目链接:https://leetcode.com/problems/edit-distance/这是一道动态规划的hard级别的问题,算法导论中有详细证明,人类的本质是复读机,就不画图细说了,这个真的想不到,代码如下:class Solution { public int minDistance(String word1, String word2) { ...

2019-01-10 14:08:20 138

原创 LeetCode--198. House Robber & 213. House Robber II

题目链接:https://leetcode.com/problems/house-robber/和https://leetcode.com/problems/house-robber-ii/问题一思路:很显然是一个动态规划问题,我们先用暴力搜索来做一遍,类似于Fibonacci数列的暴力求法,代码如下,是不是感觉跟Fibonacci数列求法基本一致呀:public static int ...

2019-01-09 22:22:57 181

原创 LeetCode--131. Palindrome Partitioning

题目链接:https://leetcode.com/problems/palindrome-partitioning/一个单词的回文串切分,使得原字符串切分得到的每个字符串都是回文串,说起来很拗口,但是暴力搜索是肯定能解释的。这里的暴力搜索:长度为n的单词到底有多少切分方式(切分得到的两部分至少有一部分是非空)呢?先看有多少个切的点?一共有n+1个可以切的点,只是后续继续切分的刀数和切分点...

2019-01-09 16:27:42 100

原创 LeetCode--125. Valid Palindrome

题目链接:https://leetcode.com/problems/valid-palindrome/这是一道很简单平常的问题,但是非常的恶心,提交了6次才AC,主要是对alphanumeric characters的理解,它的定义参考https://whatis.techtarget.com/definition/alphanumeric-alphameric。知晓了这个定义就十分轻松了,...

2019-01-09 13:28:45 100

原创 LeetCode--120. Triangle

题目链接:https://leetcode.com/problems/triangle/一看题目,感觉是暴力搜索能解,但看到问题下面有个Notes:Bonus point if you are able to do this using only O(n) extra space, where n is the total number of rows in the triangle.看到这里...

2019-01-07 22:40:38 165

原创 LeetCode--116. Populating Next Right Pointers & 117. Populating Next Right Pointers

题目链接:https://leetcode.com/problems/populating-next-right-pointers-in-each-node/和https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/。这两个问题都是基于二叉树的层次遍历来做的。但也都可以用递归来做。问题一思路一...

2019-01-07 21:42:39 97

原创 LeetCode--228. Summary Ranges

题目链接:https://leetcode.com/problems/summary-ranges/水题,双指针。代码如下:class Solution { public List<String> summaryRanges(int[] nums) { LinkedList<String> ret=new LinkedLi...

2019-01-07 16:38:21 115

原创 LeetCode--201. Bitwise AND of Numbers Range

题目链接:https://leetcode.com/problems/bitwise-and-of-numbers-range/将[m,n]区间所有值进行按位与(And)操作,返回最终的结果。思路一(Time Limited Exceed):暴力求解,代码如下:class Solution { public int rangeBitwiseAnd(int m, int n) ...

2019-01-07 16:17:26 150

原创 LeetCode--25. Reverse Nodes in k-Group

题目链接:https://leetcode.com/problems/reverse-nodes-in-k-group/这是一道hard级别的链表逆转题目,但是不难。把链表相关的easy和medium的做完再做这个应该很轻松。24. Swap Nodes in Pairs、206. Reverse Linked List、92. Reverse Linked List II这几个题目可以先做一...

2019-01-06 21:53:15 155

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除