摘要: 题目: Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'. The matching should cover the ent 阅读全文
posted @ 2018-06-11 14:30 板弓子 阅读(115) 评论(0) 推荐(0) 编辑
摘要: 题目: Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives t 阅读全文
posted @ 2018-06-09 14:23 板弓子 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 题目: Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Exam 阅读全文
posted @ 2018-06-08 17:31 板弓子 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 记数据结构中元素的个数为n 列表(List) 列表由array实现,分配的内存是一块连续空间。调取、修改列表元素,返回列表长度,这些操作的时间复杂度都是O(1).而在列表头部进行的操作时间复杂度就比较高,为O(n)。 例如,在个人本地环境中,分别从列表的尾部和头部添加10万个元素,前者花了10ms, 阅读全文
posted @ 2018-06-08 11:38 板弓子 阅读(1281) 评论(0) 推荐(0) 编辑
摘要: 题目: 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10. 思路: 注意到是依照环打印矩阵 阅读全文
posted @ 2018-06-06 22:13 板弓子 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 题目: 合并k个有序链表,并将结果用一个有序链表输出 思路: 假设k个链表的总元素数目为n。首先想到两两合并列表,在序列1和2合并,3和4合并,依次类推。直到合并的只剩一个链表。这种操作的时间复杂度为O(nlog(k)),空间复杂度为O(1)。python代码如下: 注意到在mergeTwoList 阅读全文
posted @ 2018-06-06 11:38 板弓子 阅读(1448) 评论(0) 推荐(0) 编辑
摘要: 题目: Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the 阅读全文
posted @ 2018-06-05 11:09 板弓子 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 决策树的剪枝是将生成的树进行简化,以避免过拟合。 《统计学习方法》上一个简单的方式是加入正则项a|T|,其中|T|为树的叶节点个数。 其中C(T)为生成的决策树在训练集上的经验熵,经验熵越大,表明叶节点上的数据标记越不纯,分类效果越差。有了这个标准,拿到一颗生成好的树,我们就递归的判断一组叶节点,看 阅读全文
posted @ 2018-06-04 09:33 板弓子 阅读(4249) 评论(0) 推荐(0) 编辑
摘要: 题目: Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains 阅读全文
posted @ 2018-06-03 15:59 板弓子 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 题目: Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n? Example: 提交后显示运行时间超时。原来是代码中有太多重复迭代,如同求解斐波那契数列时的直接迭代解法 阅读全文
posted @ 2018-06-03 11:57 板弓子 阅读(102) 评论(0) 推荐(0) 编辑