- 博客(252)
- 收藏
- 关注
原创 LeetCode.924 尽量减少恶意软件的传播 Minimize Malware Spread(并查集)
在节点网络中,只有当 graph[i][j] = 1 时,每个节点 i 能够直接连接到另一个节点 j。一些节点 initial 最初被恶意软件感染。只要两个节点直接连接,且其中至少一个节点受到恶意软件的感染,那么两个节点都将被恶意软件感染。这种恶意软件的传播将继续,直到没有更多的节点可以被这种方式感染。假设 M(initial) 是在恶意软件停止传播之后,整个网络中感染恶意软件的最终节点数。...
2018-10-15 14:02:42
1939
原创 LeetCode.923 三数之和的多种可能 3Sum With Multiplicity
给定一个整数数组 A,以及一个整数 target 作为目标值,返回满足 i < j < k 且 A[i] + A[j] + A[k] == target 的元组 i, j, k 的数量。由于结果会非常大,请返回 结果除以 10^9 + 7 的余数。示例 1:输入:A = [1,1,2,2,3,3,4,4,5,5], target = 8输出:20解释:按值枚举(A[i],A...
2018-10-15 13:56:16
838
原创 LeetCode 919 完全二叉树插入器 complete binary tree inserter
完全二叉树是每一层(除最后一层外)都是完全填充(即,结点数达到最大)的,并且所有的结点都尽可能地集中在左侧。设计一个用完全二叉树初始化的数据结构 CBTInserter,它支持以下几种操作:CBTInserter(TreeNode root) 使用头结点为 root 的给定树初始化该数据结构;CBTInserter.insert(int v) 将 TreeNode 插入到存在值为 node....
2018-10-11 15:47:03
597
原创 LeetCode 834.树中距离之和 Sum of distance in tree
LeetCode 834.树中距离之和 Sum of distance in tree给定一个无向、连通的树。树中有 N 个标记为 0...N-1 的节点以及 N-1 条边 。第 i 条边连接节点 edges[i][0] 和 edges[i][1] 。返回一个表示节点 i 与其他所有节点距离之和的列表 ans。示例 1:输入: N = 6, edges = [[0,1],[0,2...
2018-10-09 11:02:51
1355
1
原创 leetcode 85. Maximal Rectangle 最大矩形
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.Example:Input:[ ["1","0","1","0","0"], ["1","0","1&quo
2018-09-29 12:44:21
316
原创 leetcode 84. Largest Rectangle in Histogram 柱状图中最大的矩形
Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width of each ...
2018-09-29 11:06:11
389
原创 leetcode 714. 买卖股票的最佳时机含手续费 best-time-to-buy-and-sell-stock-with-transaction-fee
给定一个整数数组 prices,其中第 i 个元素代表了第 i 天的股票价格 ;非负整数 fee 代表了交易股票的手续费用。你可以无限次地完成交易,但是你每次交易都需要付手续费。如果你已经购买了一个股票,在卖出它之前你就不能再继续购买股票了。返回获得利润的最大值。示例 1:输入: prices = [1, 3, 2, 8, 4, 9], fee = 2输出: 8解释: 能够达...
2018-09-26 15:24:28
690
原创 leetcode 4.两个排序数组的中位数
给定两个大小为 m 和 n 的有序数组 nums1 和 nums2 。请找出这两个有序数组的中位数。要求算法的时间复杂度为 O(log (m+n)) 。你可以假设 nums1 和 nums2 不同时为空。示例 1:nums1 = [1, 3]nums2 = [2]中位数是 2.0示例 2:nums1 = [1, 2]nums2 = [3, 4]中位数是 (...
2018-09-20 14:23:35
256
原创 lintcode 186. 最多有多少个点在一条直线上
描述给出二维平面上的n个点,求最多有多少点在同一条直线上。您在真实的面试中是否遇到过这个题? 是题目纠错样例给出4个点:(1, 2), (3, 6), (0, 0), (1, 3)。一条直线上的点最多有3个。 题意很简单,思路就是二重循环枚举一下计算i点和j点的斜率K_ij,然后记录K_ij出现的次数,取最大的那个就是直线过i点的最大共线点个数。枚举完所有的i...
2018-09-13 15:51:19
939
原创 lintcode 1259. Integer Replacement 搜索
描述Given a positive integer n and you can do operations as follow:1.If n is even, replace n with n/2.2.If n is odd, you can replace n with either n + 1 or n - 1.What is the minimum number of rep...
2018-09-13 14:31:04
260
原创 131. The Skyline Problem 矩形并问题
描述水平面上有 N 座大楼,每座大楼都是矩阵的形状,可以用一个三元组表示 (start, end, height),分别代表其在x轴上的起点,终点和高度。大楼之间从远处看可能会重叠,求出 N 座大楼的外轮廓线。外轮廓线的表示方法为若干三元组,每个三元组包含三个数字 (start, end, height),代表这段轮廓的起始位置,终止位置和高度。请注意合并同样高度的相邻轮廓,不同的...
2018-09-06 17:30:53
466
原创 lintcode 1363. ZigZag Conversion 字符串处理
描述The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S...
2018-09-04 12:41:29
278
原创 协同过滤算法,python实现
在网易公开课上看了吴恩达的课。自己用python实现了一遍import numpy as npR=2alpha=0.01beta=1.0def norm_dataset(data_set,bool_set): nu=len(data_set);nm=len(data_set[0]);miu=[] for j in range(nm): sum_score...
2018-05-28 16:18:44
1563
原创 机器学习实战 第九章回归树错误
最近一直在学习《机器学习实战》这本书。感觉写的挺好,并且在网上能够轻易的找到python源码。对学习机器学习很有帮助。最近学到第九章树回归。发现代码中一再出现问题。在网上查了下,一般的网上流行的错误有两处。但是我发现源码中的错误不止这两处,还有个错误在prune里面,另外模型树的预测部分也写的很挫,奇怪的是这本书之前的代码基本上都没有犯过什么错误,这一章的代码却频繁的出现各种问题,让人匪夷所思。。首
2017-02-10 18:36:57
4365
5
原创 POJ 3368 线段树,给定区间求连续不降序列的在该区间内出现最多的数
Frequent valuesTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 13771 Accepted: 5045DescriptionYou are given a sequence of n integers a1 , a2 , ... , an
2014-12-04 15:22:41
2628
原创 Codeforces Round #179 (Div. 2) C Greg and Array
C. Greg and Arraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGreg has an array a = a1, a2, ..., an and
2013-04-12 06:50:28
2464
原创 Codeforces Round #178 (Div. 2) B Shaass and Bookshelf
B. Shaass and Bookshelftime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputShaass has n books. He wants to mak
2013-04-08 02:51:07
3124
原创 HDU 1698 线段树成段更新 Just a Hook
Just a HookTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8016 Accepted Submission(s): 3883Problem DescriptionIn the game of Dot
2012-06-04 16:59:51
3473
原创 HDU 1195 BFS,双向BFS两种写法
Open the LockTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1788 Accepted Submission(s): 747Problem DescriptionNow an emergent t
2012-05-16 16:59:22
4492
原创 HDU 4143 A Simple Problem
A Simple ProblemTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 474 Accepted Submission(s): 142Problem DescriptionFor a given pos
2011-12-22 16:17:04
2952
原创 HDU 4133 反素数
StrangeStandardTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 70 Accepted Submission(s): 31Problem DescriptionNowadays, WHUACMer
2011-12-07 18:32:21
2544
原创 百度之星2006年初赛 座位调整
1366:座位调整Time Limit:1000MS Memory Limit:65536KTotal Submit:3 Accepted:2 Page View:20[Submit] [Status] [Discuss]Font Size:AaAaAaDescription百度办公区里到处摆放着各种各样的零食。百度人力
2011-11-29 09:55:23
3295
原创 HDU 4112 2011ACM成都现场赛B
Break the ChocolateTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 46 Accepted Submission(s): 12Problem DescriptionBenjamin
2011-11-09 08:43:32
4668
2
原创 HIT OJ 1156 哈工大OJ
The Cat in the Hat Source : UVA - V1 Time limit : 1 sec Memory limit : 32 MSubmitted : 160, Accepted : 74Background(An homage to Theodore Seuss Geis
2011-11-02 15:48:39
2611
原创 HIT OJ 1087 哈工大OJ
Self Numbers Source : ACM ICPC Mid-Central USA 1998 Time limit : 5 sec Memory limit : 32 MSubmitted : 1119, Accepted : 448In 1949 the Indian mathematici
2011-10-31 20:37:39
2644
原创 HIT OJ 1076 哈工大OJ
Ordered Fractions Source : Unknown Time limit : 3 sec Memory limit : 32 MSubmitted : 1140, Accepted : 349Consider the set of all reduced fractions bet
2011-10-31 20:10:42
2353
原创 HIT OJ 1069 哈工大
Prime Land Source : ACM ICPC Central European Regional 1997 Time limit : 1 sec Memory limit : 32 MSubmitted : 238, Accepted : 133Everybody in the Prim
2011-10-31 19:57:02
1970
原创 HDU 4104
DiscountTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 89 Accepted Submission(s): 70Problem DescriptionAll the shops use d
2011-10-30 20:45:08
2561
3
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人