- 博客(310)
- 资源 (3)
- 收藏
- 关注
原创 理解Paxos算法的推导过程
Paxos作为分布式系统的基石,一直都是CS领域的热门话题,Paxos号称是最难理解的算法。最近几天一直在看Paxos相关资料,发现Paxos算法执行过程很简单,但如何推导出Paxos算法确实令人费解。网上有大量关于Paxos的基本概念、算法描述、推导过程等文章,所以关于Paxos的基本概念就不赘述了,但大部分文章都没有说明白推导过程中一些容易让人疑惑的问题(例如为什么题案要被设计为编号+value
2017-08-07 23:26:33
2131
原创 理解分布式一致性协议:二、三阶段提交
由于毕设和Lab项目需要,最近在看《从paxos到zookeeper分布式一致性原理与实践》, 2和3PC算法流程,网上资料很多,就不赘述了。由于书中关于2PC和3PC的缺点的部分描述不容易让人理解,因此本文主要想讨论一下2和3PC存在哪些优缺点?为什么存在这些缺点? 以及该协议适应的场景。2PC 二阶段提交2PC其实就是先尝试执行事务再提交的策略,如果有一个参与者出现问题,则回滚尝试期间做的事务
2017-08-07 17:15:19
1300
原创 如何构造另一个随机生成函数?
昨天下午面搜狐的时候被问到了构造随机数生成函数的问题,事后觉得有必要归纳一下相关题型。 1.已知随机数生成函数randA能等概率生成0~n的整数,设计一个等概率生成0~m的randB算法: 若n大于m,则直接利用randA随机产生的数作为randB,如果randA产生的数大于m则丢弃这个数,重新产生,直至成功。若n远大于m,则只需构造最大值为m*(n/m)的随机函数randC,然后丢弃ran
2017-08-03 14:25:49
1720
原创 【Leet】453. Minimum Moves to Equal Array Elements
题目链接:https://leetcode.com/problems/minimum-moves-to-equal-array-elements/题目:Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equa
2016-11-08 08:53:30
2725
原创 【hihocoder】#1051 : 补提交卡
题目链接:http://hihocoder.com/problemset/problem/1051题目: 描述 小Ho给自己定了一个宏伟的目标:连续100天每天坚持在hihoCoder上提交一个程序。100天过去了,小Ho查看自己的提交记录发现有N天因为贪玩忘记提交了。于是小Ho软磨硬泡、强忍着小Hi鄙视的眼神从小Hi那里要来M张”补提交卡”。每张”补提交卡”都可以补回一天的提交,将原本没有提交
2016-10-04 15:16:35
1404
原创 【hihocoder】#1094 : Lost in the City
题目链接:http://hihocoder.com/problemset/problem/1094题目: 描述 Little Hi gets lost in the city. He does not know where he is. He does not know which direction is north.Fortunately, Little Hi has a map of th
2016-10-04 15:12:00
1480
原创 【Leetcode】Convert a Number to Hexadecima
题目链接:https://leetcode.com/problems/convert-a-number-to-hexadecimal/题目:Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used
2016-10-03 14:21:59
1466
原创 【Leetcode】410. Split Array Largest Sum
题目链接:https://leetcode.com/contest/7/problems/split-array-largest-sum/]题目:Given an array which consists of non-negative integers and an integer m, you can split the array into m non-empty con
2016-10-02 13:19:52
4852
原创 【Leetcode】408. Valid Word Abbreviation
题目链接:https://leetcode.com/contest/7/problems/valid-word-abbreviation/题目: Given a non-empty string s and an abbreviation abbr, return whether the string matches with the given abbreviation.A string suc
2016-10-02 13:09:02
3085
原创 【Leetcode】409. Longest Palindrome
题目链接:https://leetcode.com/contest/7/problems/longest-palindrome/题目: Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with t
2016-10-02 13:04:32
1978
原创 【Leetcode】402. Remove K Digits
题目链接:https://leetcode.com/contest/5/problems/remove-k-digits/题目: Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possib
2016-09-18 14:24:53
3382
原创 【Leetcode】400. Nth Digit
题目链接:https://leetcode.com/contest/5/problems/nth-digit/题目: Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, … Note: n is positive and will fit within the range
2016-09-18 13:58:43
6382
原创 【Leetcode】401. Binary Watch
题目链接:https://leetcode.com/contest/5/problems/binary-watch/题目: A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).Each LED
2016-09-18 13:48:33
3152
原创 【Hihocoder】#1049 : 后序遍历
题目链接:http://hihocoder.com/problemset/problem/1049题目描述:没错!小Ho在这一周遇到的问题便是:给出一棵二叉树的前序和中序遍历的结果,还原这棵二叉树并输出其后序遍历的结果。输入每个测试点(输入文件)有且仅有一组测试数据。每组测试数据的第一行为一个由大写英文字母组成的字符串,表示该二叉树的前序遍历
2016-09-17 12:56:27
1204
原创 【hihocoder】1141 : 二分·归并排序之逆序对
题目链接:http://hihocoder.com/problemset/problem/1141题目:我们可以看到,船默认排序是以等级为参数。但实际上一个船的火力值和等级的关系并不大,所以会存在A船比B船等级高,但是A船火力却低于B船这样的情况。比如上图中77级的飞龙改二火力就小于55级的夕立改二。现在Nettle将按照等级高低的顺序给出所有船的火力值,请你计算出一共有多少对船满
2016-09-16 19:37:45
1348
原创 【hihocoder】#1366 : 逆序单词
题目链接:http://hihocoder.com/problemset/problem/1366思路:easy ,不解释算法:import java.util.HashSet;import java.util.Scanner;import java.util.Set;/** * http://hihocoder.com/problemset/problem
2016-09-16 19:21:52
1201
原创 【hihocoder】1014 : Trie树
题目懒得贴了。。http://hihocoder.com/problemset/problem/1014思路:easy。。trie树。。。。不同点在于。。为了查询前缀效率更高,在该树中添加节点时,在添加过程中的节点都记录一下以该节点为父节点有多少个子节点。。。。。(说的我头都晕了,其实就是add word时,从root到新节点经过的路径上的每个节点记录值都加一)
2016-09-16 19:19:55
884
原创 【hihocoder】#1039 : 字符消除
题目:小Hi最近在玩一个字符消除游戏。给定一个只包含大写字母"ABC"的字符串s,消除过程是如下进行的:1)如果s包含长度超过1的由相同字母组成的子串,那么这些子串会被同时消除,余下的子串拼成新的字符串。例如"ABCCBCCCAA"中"CC","CCC"和"AA"会被同时消除,余下"AB"和"B"拼成新的字符串"ABB"。2)上述消除会反复一轮一轮进行,直到新的字符串不包含
2016-09-16 19:06:14
1124
原创 【Leetcode】386. Lexicographical Numbers
题目链接:https://leetcode.com/problems/lexicographical-numbers/ 题目: Given an integer n, return 1 - n in lexicographical order.For example, given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9].Please optimiz
2016-09-15 16:29:48
1966
原创 【Leetcode】Shortest Palindrome
题目链接:https://leetcode.com/problems/shortest-palindrome/ 题目: Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrom
2016-09-13 15:02:01
857
原创 【Leetcode】398. Random Pick Index
题目链接:https://leetcode.com/contest/4/problems/random-pick-index/题目:Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that t
2016-09-11 21:22:49
3729
原创 【Leetcode】397. Integer Replacement
题目链接:https://leetcode.com/contest/4/problems/integer-replacement/题目:Given a positive integer n and you can do operations as follow:If n is even, replace n with n/2.If n is odd, you can
2016-09-11 21:19:35
3959
原创 【Leetcode】396. Rotate Function
题目链接:题目:Given an array of integers A and let n to be its length.Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define a "rotation function" F on A as
2016-09-11 21:15:46
3077
原创 【Leetcode】399. Evaluate Division
题目链接:https://leetcode.com/contest/4/problems/evaluate-division/题目:Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (flo
2016-09-11 21:12:15
5387
原创 【Leetcode】Remove Duplicate Letters
题目链接:https://leetcode.com/problems/remove-duplicate-letters/题目:Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. Yo
2016-09-10 20:21:44
811
原创 【Leetcode】Range Sum Query - Mutable
题目链接:https://leetcode.com/problems/range-sum-query-mutable/题目:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.The update(i, val) functi
2016-09-08 11:09:35
718
原创 【Leetcode】UTF-8 Validation
题目链接:https://leetcode.com/problems/utf-8-validation/题目:A character in UTF8 can be from 1 to 4 bytes long, subjected to the following rules:For 1-byte character, the first bit is a 0, follo
2016-09-07 19:41:10
2073
原创 【Leetcode】395. Longest Substring with At Least K Repeating Characters
题目链接:https://leetcode.com/problems/longest-substring-with-at-least-k-repeating-characters/题目:Find the length of the longest substring T of a given string (consists of lowercase letters only) s
2016-09-06 21:22:22
1868
原创 【Leetcode】Is Subsequence
题目链接:https://leetcode.com/contest/3/problems/is-subsequence/题目:Given a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters
2016-09-04 22:40:01
1892
原创 【Leetcode】394. Decode String
题目链接:https://leetcode.com/contest/3/problems/decode-string/题目:Given an encoded string, return it's decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the s
2016-09-04 22:37:25
1761
原创 【Leetcode】Two Sum II - Input array is sorted
题目链接:https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/题目:Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specifi
2016-09-01 09:37:55
1345
3
原创 【Leetcode】Longest Absolute File Path
题目链接:https://leetcode.com/problems/longest-absolute-file-path/题目:Suppose we abstract our file system by a string in the following manner:The string "dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext
2016-08-30 14:47:26
2884
原创 【Leetcode】Mini Parser
题目链接:https://leetcode.com/problems/mini-parser/题目:Given a nested list of integers represented as a string, implement a parser to deserialize it.Each element is either an integer, or a list -
2016-08-15 09:52:03
3550
原创 【Leetcode】Shuffle an Array
题目链接:https://leetcode.com/problems/shuffle-an-array/题目:Shuffle a set of numbers without duplicates.Example:// Init an array with set 1, 2, and 3.int[] nums = {1,2,3};Solution solution
2016-08-12 21:39:35
3235
原创 【Leetcode】Ransom Note
题目链接:https://leetcode.com/problems/ransom-note/题目:Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that wi
2016-08-12 07:31:31
3015
原创 【Leetcode】Linked List Random Node
题目链接:https://leetcode.com/problems/linked-list-random-node/题目:Given a singly linked list, return a random node's value from the linked list. Each node must have the same probability of being c
2016-08-10 11:09:03
2344
转载 Reservoir Sampling - 蓄水池抽样
问题起源于编程珠玑Column 12中的题目10,其描述如下: How could you select one of n objects at random, where you see the objects sequentially but you do not know the value of n beforehand? For concreteness, how woul
2016-08-10 11:00:36
1395
原创 【Leetcode】Insert Delete GetRandom O(1) - Duplicates allowed
题目链接:https://leetcode.com/problems/insert-delete-getrandom-o1-duplicates-allowed/题目:Design a data structure that supports all following operations in average O(1) time.Note: Duplicate elemen
2016-08-09 22:19:11
2686
原创 【Leetcode】Insert Delete GetRandom O(1)
题目链接:https://leetcode.com/problems/insert-delete-getrandom-o1/题目:Design a data structure that supports all following operations in average O(1) time.insert(val): Inserts an item val to
2016-08-07 09:14:08
4493
原创 【Leetcode】Kth Smallest Element in a Sorted Matrix
题目链接:https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/题目:Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest eleme
2016-08-01 21:54:16
4124
java 贴吧合影小程序
2012-12-26
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人