Go concurrent crawler 下面是a tour of go 中最后一个练习的解法,本文使用了真正的网络io来运行爬虫,由于没有对连接数做限制,所以当depth为3时会发生错误package mainimport ( "fmt" "log" "strings" "sync" "github.com/PuerkitoBio/goquery")type Fetcher interface {
rot13Reader package mainimport ( "io" "os" "strings")type rot13Reader struct { r io.Reader}func (rot rot13Reader) Read(b []byte) (n int, err error){ left:=len(b) for{ length,stat
397. Longest Increasing Continuous Subsequence class Solution: """ @param: A: An array of Integer @return: an integer """ def longestIncreasingContinuousSubsequence(self, A): # write your code here if len(A)==0:
115. Unique Paths II class Solution: """ @param: obstacleGrid: A list of lists of integers @return: An integer """ def uniquePathsWithObstacles(self, obstacleGrid): # write your code here
114. Unique Paths class Solution: """ @param: m: positive integer (1 <= m <= 100) @param: n: positive integer (1 <= n <= 100) @return: An integer """ def uniquePaths(self, m, n): # write
111. Climbing Stairs class Solution: """ @param n: An integer @return: An integer """ def climbStairs(self, n): # write your code here if n==0: return 0 if n==1:
110.Minimum Path Sum class Solution: """ @param: grid: a list of lists of integers @return: An integer, minimizes the sum of all numbers along its path """ def minPathSum(self, grid): # write yo
109.triangle class Solution: """ @param: triangle: a list of lists of integers @return: An integer, minimum path sum """ def minimumTotal(self, triangle): # write your code here
514. Paint Fence class Solution {public: /* * @param n: non-negative integer, n posts * @param k: non-negative integer, k colors * @return: an integer, the total number of ways */ int numWa
kmp算法 #define MAX 10000void getNext(char *p,int next[]){ int p_len=strlen(p); next[0]=-1; next[1]=0; for (int i=2;i<p_len;i++){ int q=next[i-1]; while (q!=0 && p[q]!=p[i-1])
最长递增子序列(nlogn) #define MAX 1000000int find(int a[],int x,int l,int r){ while (l<=r){ int mid=(l+r)/2; if (a[mid]==x) return mid; if (a[mid]<x) l=mid+1; els
排序算法大合集 #include<stdlib.h>#include<unistd.h>#include<stdio.h>#include<unistd.h>#include<sys/wait.h>#include<time.h>#define MAX 10000int check(int a[],int n){ for (int i=0;i<n-1;i++) if (a[i]>
4.1.3求值器数据结构 ;4.12,这里的用了一个通用的在框架中寻找变量的过程,不过这个过程不能用在4.13中的make-unbound!里(define (lookup-var-in-frame var vars vals) (cond ((null? vars) false) ((eq? var (car vars)) (cons vars vals)) (else (lookup
函数式程序的模块化和对象的模块化 (define random-init 1)(define (rand-update x) (remainder (+ (* 13 x) 5) 24))(define (random-numbers op-stream) (define (numbers last-value op-stream) (let ((op (stream-car op-stream)))
流和延时求值 ;书上的let并不是必须的(define (integral delayed-integrand initial-value dt) (define int (cons-stream initial-value (add-streams (scale-stream (force delaye
序对的无穷流 (define (interleave s1 s2) (if (empty-stream? s1) s2 (cons-stream (stream-car s1) (interleave s2 (stream-cdr s1)))))(define (pairs s t) (cons-stream (list (stream-ca
流计算模式的使用 ;系统地将迭代操作方式表示为流过程(define (sqrt-stream x) (define guesses (cons-stream 1.0 (stream-map (lambda (guess) (/ (+ guess (/ x guess)) 2)) guesses)))
流(3.5.1~3.5.2) ;流实现的行为方式;delay和force的实现(define (memo-proc proc) (let ((already-run? false) (result false)) (lambda () (if already-run? result (begin (set! already-run? tr
约束的传播 ;连接器的表示;user不需要也不能添加进constraints表里面,并且只有实现connect过的constraint才能进行set-value!(define (make-connector) (let ((value false) (informant false) (constraints '())) (define (set-my-value! new-value set