摘要: 1 import random 2 3 def partition(A, lo, hi): 4 pivot_index = random.randint(lo, hi) 5 pivot = A[pivot_index] 6 A[pivot_index], A[hi] = ... 阅读全文
posted @ 2015-02-26 14:18 Justin.cn 阅读(229) 评论(0) 推荐(0) 编辑
摘要: An Python implementation of heap-sortbased on the detailed algorithm description in Introduction to Algorithms Third Editionimport randomdef max_heap... 阅读全文
posted @ 2015-02-25 21:54 Justin.cn 阅读(239) 评论(0) 推荐(0) 编辑
摘要: Total Accepted: 12400 Total Submissions: 83230Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 < version... 阅读全文
posted @ 2015-02-21 20:14 Justin.cn 阅读(200) 评论(0) 推荐(0) 编辑
摘要: 1 a = range(3)2 b = range(3)3 [ (x, y) for x, y in zip(a, b) ]结果:1 [ (0,0), (1,1), (2,2) ]当然,如上可以推广到多个列表。 阅读全文
posted @ 2015-02-21 17:56 Justin.cn 阅读(2368) 评论(0) 推荐(0) 编辑
摘要: Total Accepted: 3790 Total Submissions: 21072All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T,for example: "ACGAATTCCG".Wh... 阅读全文
posted @ 2015-02-19 11:53 Justin.cn 阅读(224) 评论(0) 推荐(0) 编辑
摘要: Total Accepted: 31557 Total Submissions: 116793Given a triangle, find the minimum path sum from top to bottom.Each step you may move to adjacent numbe... 阅读全文
posted @ 2015-02-18 16:33 Justin.cn 阅读(210) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 int strStr(char *haystack, char *needle) { 4 5 int i = 0 , skip[256]; 6 char *str = haystack, *substr = n... 阅读全文
posted @ 2015-02-18 13:00 Justin.cn 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), ne... 阅读全文
posted @ 2015-02-18 12:56 Justin.cn 阅读(260) 评论(0) 推荐(0) 编辑
摘要: 1 #define ADDITION '+' 2 #define SUBSTRACTION '-' 3 #define MULTIPLICATION '*' 4 #define DIVISION '/' 5 6 7 class Solution { 8 public: 9 se... 阅读全文
posted @ 2015-02-18 12:52 Justin.cn 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 vector ret; 4 string src; 5 int len; 6 unordered_set added; 7 vector restoreIpAddresses(string... 阅读全文
posted @ 2015-02-18 12:47 Justin.cn 阅读(171) 评论(0) 推荐(0) 编辑