
算法
文章平均质量分 95
zdxiq000
这个作者很懒,什么都没留下…
展开
-
并发编程:聊聊常用的并发同步模板
我们从一道简单的题出发,覆盖了并发场景下经常会遇到的几种变成模式,这里面的每一种都值得我们细细去理解,并熟练掌握。对于并发包里给出的大量同步工具,我想不同工具会有自己的适用场景,而信号量(Semaphore)是一种必须掌握的工具。其他工具我也会另做总结。原创 2023-06-02 16:21:28 · 793 阅读 · 0 评论 -
再谈大量数据去重:字典树(Trie)和外排序(External Sorting)
空间、时间是一对孪生兄弟。算法道路上,大家都有一个共识,“时空"可以互换。有没有办法利用更多的时间来换取有限内存下的大量数据去重呢?今天我们再来一探究竟。原创 2021-06-06 01:50:36 · 1341 阅读 · 2 评论 -
[Leetcode 451] Sort Characters By Frequency
451. Sort Characters By Frequency451. 根据字符出现频率排序IntuitionCount all the characters and rebuild the output string by sorting.ComplexityTime: O(nlogn), where n is the length of input string.Space...原创 2020-03-11 12:47:26 · 338 阅读 · 0 评论 -
[Leetcode 393] UTF-8 Validation
393. UTF-8 Validation393. UTF-8 编码验证IntuitionIt’s obviously a bit manipulation problem. But also there are lots of states need to be considered. An encoded UTF-8 character is possiblely represented...原创 2020-03-05 11:39:07 · 247 阅读 · 0 评论 -
[Leetcode 1326] Minimum Number of Taps to Open to Water a Garden
1326. Minimum Number of Taps to Open to Water a Garden1326. 灌溉花园的最少水龙头数目IntuitionWe can build a interval for each tap representing the area it covers. Each time we pick an interval, we choose the o...原创 2020-03-01 12:14:05 · 549 阅读 · 0 评论 -
[Leetcode 979] Distribute Coins in Binary Tree
In order to distribute coins, every node has following tasks:take the coins from the subtree who has more coins than nodesgive the coins to the substree who has less coins than nodesdistrubte the ...原创 2020-02-26 16:31:33 · 342 阅读 · 0 评论 -
[Leetcode 1191] K-Concatenation Maximum Sum
原题直达:K-Concatenation Maximum Sum首先,关于“最大子数组和”问题有一个基于动态规划的经典算法Kadane算法。这个算法使用maxOfEnd表示以当前数组元素结尾的最大和子数组,转移过程也十分简单——要么就是只取当前元素,要么就是拖家带口把前一元素的maxOfEnd一起带上。上图的例子,我们使用以下的Kadane算法,可以得到最大子数组和为55 + 66 = 121...原创 2020-01-08 20:45:43 · 562 阅读 · 0 评论 -
[Leetcode] LRU Cache
题目来源:LRU CacheDesign and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.get(key) - Get the value (will always be positive) o...原创 2019-08-13 15:15:48 · 262 阅读 · 0 评论 -
大量数据去重:Bitmap和布隆过滤器(Bloom Filter)
5TB的硬盘上放满了数据,请写一个算法将这些数据进行排重。如果这些数据是一些32bit大小的数据该如何解决?如果是64bit的呢?在面试时遇到的问题,问题的解决方案十分典型,但对于海量数据处理接触少的同学可能一时也想不到什么好方案。介绍两个算法,对于空间的利用到达了一种极致,那就是Bitmap和布隆过滤器(Bloom Filter)。原创 2017-02-27 17:46:27 · 63381 阅读 · 19 评论 -
字符串搜索之Boyer-Moore算法
在用于查找子字符串的算法当中,BM(Boyer-Moore)算法是目前被认为最高效的字符串搜索算法,它由Bob Boyer和J Strother Moore设计于1977年。 一般情况下,比KMP算法快3-5倍。该算法常用于文本编辑器中的搜索匹配功能,比如大家所熟知的GNU grep命令使用的就是该算法。转载 2015-07-29 19:54:41 · 488 阅读 · 0 评论