This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int ladderLength(string start, string end, unordered_set<string> &dict) { | |
dict.insert(start); dict.insert(end); | |
queue< pair<string, int> > q; | |
unordered_set<string> visited; | |
q.push(make_pair(start, 1)); | |
int res = 0; | |
while (!q.empty()) { | |
pair<string, int> top = q.front(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Solving POJ 3461 Oulipo */ | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
class KMP_algorithm { | |
private: | |
vector<int> next; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Jie Bao, 2013-07-16 | |
# [email protected] | |
# simple Naive Bayes classifier | |
import nltk | |
from nltk.corpus import movie_reviews | |
import random | |
import os | |
import json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Solving POJ 2406 Power Strings */ | |
#include <iostream> | |
#include <cstring> | |
using namespace std; | |
class KMP_algorithm { | |
public: | |
int find_base(const char* pattern) { | |
/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Solving POJ 1961 Period */ | |
#include <iostream> | |
#include <cstring> | |
using namespace std; | |
char input[1000005]; | |
int next[1000006]; | |
class KMP_algorithm { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Solving POJ 2752 Seek the Name, Seek the Fame */ | |
#include <iostream> | |
#include <cstring> | |
using namespace std; | |
char input[400005]; | |
int next[400006]; | |
int q[200003]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
for instructions, check | |
https://www.evernote.com/shard/s46/sh/5353dced-48b4-4158-9a8f-46607d810845/2dc3d625ef7263de7ccfeda0ab7dd0e2 | |
and archived note in google keep. | |
btw: I failed this problem T^T | |
''' | |
def nCr(n, r): | |
from itertools import izip | |
return reduce(lambda x, y: x * y[0] / y[1], izip(xrange(n - r + 1, n+1), xrange(1, r+1)), 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding:utf-8 | |
import urllib2 | |
import json | |
import peewee | |
from datetime import date, timedelta | |
from BeautifulSoup import BeautifulSoup | |
today = date.today() | |
one_day = timedelta(days=1) | |
date_i = date(2013,5,20) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from lxml import etree | |
# parse | |
parser = etree.XMLParser(ns_clean=True) # support other arguments | |
tree = etree.parse(some_file_like_obj) | |
# could be file name/path, file-like object, http/ftp url. but | |
# name/path and url are faster. or from string as following | |
tree = etree.fromstring(string, parser) | |
tree = etree.XML('<root><a><b/></a></root>') |
OlderNewer