算法
文章平均质量分 60
bachelorchen
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
求一个二进制数的(二进制表示)的所有子集
http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=bitManipulation iterate over all the subsets of a particular subset (represented by a bit pattern) So the iteration step is just i原创 2013-06-14 14:32:44 · 1031 阅读 · 0 评论 -
redis, dict, hashtable
two hash functions/* And a case insensitive hash function (based on djb hash) */unsigned int dictGenCaseHashFunction(const unsigned char *buf, int len) { unsigned int hash = (unsigned int)dict_原创 2014-06-02 17:12:51 · 603 阅读 · 0 评论 -
PCA
Pattern recognition and machine learningPrin原创 2014-06-26 21:54:55 · 435 阅读 · 0 评论 -
redis sorted set
The t_zset.c contains the sorted set code.work to do:原创 2014-06-05 23:09:51 · 448 阅读 · 0 评论 -
LRU Cache
The following are either implementations, "napkin designs" or discussions of LRU caches in C++:http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.88.7296&rep=rep1&type=pdfhttp://www.bott原创 2014-05-28 23:11:29 · 748 阅读 · 0 评论 -
do{}while(0);
第一次在 redis 的 dict 源码中看到这种用法。原创 2014-05-29 17:50:14 · 621 阅读 · 0 评论 -
leetcode 日经贴,python code - 3sum
https://oj.leetcode.com/problems/3sum/class Solution: # @return a list of lists of length 3, [[val1,val2,val3]] def threeSum(self, num): num.sort() lst = [] n = len(n原创 2015-02-09 11:19:31 · 387 阅读 · 0 评论 -
leetcode 日经贴,python code - 3sumClosest
https://oj.leetcode.com/problems/3sum-closest/class Solution: # @return an integer def threeSumClosest(self, num, target): num.sort() n = len(num) if (n < 3): return原创 2015-02-09 11:45:12 · 409 阅读 · 0 评论 -
leetcode 日经贴,python code -Palindrome Number
Palindrome Numberclass Solution: # @return a boolean def isPalindrome(self, x): if x < 0: return False y, z = 0, x while z: y = y * 10 + z % 10原创 2015-02-16 14:37:52 · 609 阅读 · 0 评论 -
leetcode 日经贴,python code -Symmetric Tree
Symmetric Tree# Definition for a binary tree node# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution:原创 2015-02-21 16:25:28 · 390 阅读 · 0 评论 -
leetcode 日经贴,python code -insert-interval
insert-interval# Definition for an interval.# class Interval:# def __init__(self, s=0, e=0):# self.start = s# self.end = eclass Solution: # @param intervals, a list of原创 2015-02-09 19:00:06 · 468 阅读 · 0 评论 -
leetcode 日经贴,python code -Gas Station
Gas Stationclass Solution: # @param gas, a list of integers # @param cost, a list of integers # @return an integer def canCompleteCircuit(self, gas, cost): n = len(gas)原创 2015-02-09 20:38:33 · 355 阅读 · 0 评论 -
leetcode 日经贴,python code -Remove Duplicates from Sorted Array
Remove Duplicates from Sorted Arrayclass Solution: # @param a list of integers # @return an integer def removeDuplicates(self, A): n = len(A) if n <= 1: return n原创 2015-02-17 13:24:31 · 396 阅读 · 0 评论 -
leetcode 日经贴,python code -repeated-dna-sequences
https://oj.leetcode.com/problems/repeated-dna-sequences/class Solution: # @param s, a string # @return a list of strings def findRepeatedDnaSequences(self, s): map2Int = {'A':0,原创 2015-02-09 20:16:25 · 632 阅读 · 0 评论 -
leetcode 日经贴,python code -Excel Sheet Column Title
Excel Sheet Column Titleclass Solution: # @return a string def convertToTitle(self, num): s = "" while num > 0: r = (num - 1) % 26 + 1 s = chr(ord原创 2015-02-09 20:58:45 · 485 阅读 · 0 评论 -
leetcode 日经贴,python code -Median of Two Sorted Arrays
Median of Two Sorted Arraysclass Solution: # @return an element from A or B def findKth(self, A, B, k): n, m = len(A), len(B) if n == 0: return B[k - 1] if m == 0:原创 2015-02-17 13:49:38 · 350 阅读 · 0 评论 -
leetcode 日经贴,python code -Balanced Binary Tree
Balanced Binary Tree# Definition for a binary tree node# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = Nonecla原创 2015-02-11 12:14:29 · 446 阅读 · 0 评论 -
leetcode 日经贴,python code -Valid Parentheses
Valid Parenthesesclass Solution: # @return a boolean def isValid(self, s): st = [] for x in s: if x in ('(', '[', '{'): st.append(x) e原创 2015-02-10 22:38:02 · 391 阅读 · 0 评论 -
leetcode 日经贴,python code -Find Peak Element
Find Peak Elementclass Solution: # @param num, a list of integer # @return an integer def findPeakElement(self, num): n = len(num) if n <= 1: return 0原创 2015-02-11 12:23:41 · 469 阅读 · 0 评论 -
leetcode 日经贴,python code -Next Permutation
Next Permutationclass Solution: # @param num, a list of integer # @return a list of integer def nextPermutation(self, num): if len(num) < 2: return num n = len(num)原创 2015-02-10 23:05:54 · 376 阅读 · 0 评论 -
leetcode 日经贴,python code -Remove Element
Remove Elementclass Solution: # @param A a list of integers # @param elem an integer, value need to be removed # @return an integer def removeElement(self, A, elem):原创 2015-02-11 11:54:22 · 355 阅读 · 0 评论 -
leetcode 日经贴,python code -Reverse Words in a String
Reverse Words in a Stringclass Solution: # @param s, a string # @return a string def reverseWords(self, s): return ' '.join(s.split()[::-1])原创 2015-02-13 12:35:13 · 412 阅读 · 0 评论 -
leetcode 日经贴,python code -Unique Paths
Unique Pathsclass Solution: # @return an integer def uniquePaths(self, m, n): numerator, denominator = 1, 1 for i in range(m - 1): numerator *= i + 1原创 2015-02-16 14:57:22 · 431 阅读 · 0 评论 -
leetcode 日经贴,python code -Copy List with Random Pointer
Copy List with Random Pointer# Definition for singly-linked list with a random pointer.# class RandomListNode:# def __init__(self, x):# self.label = x# self.next = None#原创 2015-02-15 10:27:54 · 474 阅读 · 0 评论 -
leetcode 日经贴,python code -Surrounded Regions
Surrounded Regionsclass Solution: # @param board, a 2D array # Capture all regions by modifying the input board in-place. # Do not return any value. def solve(self, board):原创 2015-02-15 10:29:20 · 360 阅读 · 0 评论 -
leetcode 日经贴,python code -Longest Valid Parentheses
Longest Valid Parenthesesclass Solution: # @param s, a string # @return an integer def longestValidParentheses(self, s): ret, st = 0, [] st.append((-1,')')) for原创 2015-02-16 14:48:21 · 393 阅读 · 0 评论 -
leetcode 日经贴,python code -Sqrt(x)
Sqrt(x)class Solution: # @param x, an integer # @return an integer def sqrt(self, x): if x <= 1: return x low, high = 1, x while low < high:原创 2015-02-13 12:44:26 · 949 阅读 · 0 评论 -
leetcode 日经贴,python code -Spiral Matrix
Spiral Matrixclass Solution: # @param matrix, a list of lists of integers # @return a list of integers def spiralOrder(self, matrix): n = len(matrix) if n == 0: return []原创 2015-02-13 17:05:49 · 390 阅读 · 0 评论 -
Box Stacking
Box stacking: You are given a set of boxes {b1, ..., bn}. Each box bj has an associated width wj ,height hj and depth dj . Give an algorithm for creating the highest possible stack of boxes with the原创 2015-02-15 16:41:10 · 614 阅读 · 0 评论 -
leetcode 日经贴,Cpp code -Maximum Subarray
Maximum Subarrayclass Solution {public: int maxSubArray(int A[], int n) { int ans = 0, cs = 0; if (n == 0) return 0; ans = cs = A[0]; for (int i = 1; i < n; ++原创 2015-03-19 09:54:23 · 350 阅读 · 0 评论 -
leetcode 日经贴,Cpp code -Interleaving String
Interleaving Stringclass Solution {public: bool isInterleave(string s1, string s2, string s3) { int n = s1.length(), m = s2.length(), l3 = s3.length(); if (n + m != l3)原创 2015-03-19 09:49:57 · 339 阅读 · 0 评论 -
leetcode 日经贴,Cpp code -Valid Parentheses
Valid Parenthesesclass Solution {public: bool leftBrace(char ch) { return ch == '(' || ch == '{' || ch == '['; } bool isMatch(char lc, char rc) { return lc == '(' && r原创 2015-03-19 10:00:41 · 352 阅读 · 0 评论 -
leetcode 日经贴,Cpp code -Palindrome Partitioning II
Palindrome Partitioning IIclass Solution {public: int minCut(string s) { int n = s.length(); if (n <= 1) return 0; vector > dp; dp.resize(n); for (int原创 2015-03-16 10:10:09 · 329 阅读 · 0 评论 -
leetcode 日经贴,Cpp code -Sort Colors
Sort Colorsclass Solution {public: void swap(int &a, int &b) { int c = a; a = b; b = c; } void sortColors(int A[], int n) { const int red = 0, white =原创 2015-03-16 10:19:32 · 350 阅读 · 0 评论 -
leetcode 日经贴,Cpp code -Median of Two Sorted Arrays
Median of Two Sorted Arraysclass Solution {public: int findkth(int* A, int m, int* B, int n, int k) { if (m + n < k) { return -1; //out of range } if (m ==原创 2015-03-16 14:24:02 · 329 阅读 · 0 评论 -
POJ 1470 Closest Common Ancestors - Tarjan
POJ 1470 Closest Common AncestorsWiki 上的 Tarjan 算法, Tarjan is an offline algorithmhttp://en.wikipedia.org/wiki/Tarjan's_off-line_lowest_common_ancestors_algorithmfunction TarjanOLCA(u) Ma原创 2015-03-20 11:37:43 · 474 阅读 · 0 评论 -
leetcode 日经贴,Cpp code -Path Sum II
Path Sum II/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * };原创 2015-03-16 22:55:15 · 336 阅读 · 0 评论 -
leetcode 日经贴,Cpp code -Scramble String
Scramble Stringclass Solution {public: bool isScramble2(string s1, string s2) { int n = s1.length(); if (n <= 3) return true; //from left int match = 0;原创 2015-03-17 10:57:29 · 529 阅读 · 0 评论 -
leetcode 日经贴,python code -Decode Ways
Decode Waysclass Solution: # @param s, a string # @return an integer def numDecodings(self, s): n = len(s) if n == 0: return 0 if n == 1: if '1' <=原创 2015-03-23 20:37:53 · 358 阅读 · 0 评论 -
leetcode 日经贴,python code -Remove Element
Remove Elementclass Solution: # @param A a list of integers # @param elem an integer, value need to be removed # @return an integer def removeElement(self, A, elem):原创 2015-03-23 20:43:38 · 357 阅读 · 0 评论
分享