Skip to content

Commit d89d4eb

Browse files
authored
Merge branch 'master' into master
2 parents 50f46be + 5a0bca8 commit d89d4eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2933
-988
lines changed

.travis.yml

+51-95
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,76 @@
1+
sudo: required
2+
13
language: node_js
24

35
node_js:
4-
- "stable"
6+
- stable
57

68
before_install:
7-
- echo "add id_rsa private key"
8-
- openssl aes-256-cbc -K $encrypted_c2697660bfd7_key -iv $encrypted_c2697660bfd7_iv
9-
-in id_rsa.enc -out ~/.ssh/id_rsa -d
10-
- chmod 600 ~/.ssh/id_rsa
11-
- eval "$(ssh-agent -s)"
12-
- ssh-add ~/.ssh/id_rsa
13-
- cp ssh_config ~/.ssh/config
14-
- git config --global user.name "rhett"
15-
- git config --global user.email yuanbin2014@gmail.com
16-
# update first
17-
- sudo apt-get update -qq
18-
# Install Gitbook
199
- npm install gitbook-cli -g
2010
- npm install svgexport -g
11+
- gitbook fetch 3.2.3
12+
- sudo apt-get update -qq
2113
# install calibre latest version
2214
- sudo -v && wget --no-check-certificate -nv -O- https://raw.githubusercontent.com/kovidgoyal/calibre/master/setup/linux-installer.py | sudo python -c "import sys; main=lambda:sys.stderr.write('Download failed\n'); exec(sys.stdin.read()); main()"
2315

24-
before_script:
25-
- cd ~
26-
- wget http://devtools.qiniu.io/qiniu-devtools-linux_amd64-current.tar.gz
27-
- tar xfz qiniu-*.tar.gz
28-
- git clone https://github.com/billryan/algorithm-exercise.git ~/algorithm-exercise
29-
- echo "install gitbook plugins..."
30-
- cd ~/algorithm-exercise/
31-
- cp LANGS.md LANGS_bak.md
16+
install:
3217
- gitbook install
33-
- cp ~/algorithm-exercise/scripts/rename_ebook.sh ~/
34-
- cp ~/algorithm-exercise/conf/qiniu_sync.json ~/
35-
- sed -i "s/AccessKey/$QAK/g" ~/qiniu_sync.json
36-
- sed -i "s/SecretKey/$QSK/g" ~/qiniu_sync.json
37-
- mkdir -p ~/upload
38-
- mkdir -p ~/raw_fonts
18+
19+
before_script:
20+
- cp LANGS.md LANGS.md.bak
3921
- mkdir -p ~/.fonts/noto
40-
- mkdir -p ~/.fonts/arial
22+
- mkdir -p ~/raw_fonts/{NotoSans-unhinted,NotoSansCJKsc-hinted,NotoSansCJKtc-hinted}
23+
- wget -P ~/raw_fonts https://noto-website-2.storage.googleapis.com/pkgs/NotoSans-unhinted.zip
24+
- unzip ~/raw_fonts/NotoSans-unhinted.zip -d ~/raw_fonts/NotoSans-unhinted
25+
- wget -P ~/raw_fonts https://noto-website-2.storage.googleapis.com/pkgs/NotoSansCJKsc-hinted.zip
26+
- unzip ~/raw_fonts/NotoSansCJKsc-hinted.zip -d ~/raw_fonts/NotoSansCJKsc-hinted
27+
- wget -P ~/raw_fonts https://noto-website-2.storage.googleapis.com/pkgs/NotoSansCJKtc-hinted.zip
28+
- unzip ~/raw_fonts/NotoSansCJKtc-hinted.zip -d ~/raw_fonts/NotoSansCJKtc-hinted
4129

4230
script:
43-
- echo "build English ebook..."
44-
# - wget -P ~/raw_fonts https://noto-website.storage.googleapis.com/pkgs/NotoSans-unhinted.zip
45-
# - wget -P ~/raw_fonts https://github.com/billryan/algorithm-exercise/files/277714/migu-1m-20150712.zip
46-
- wget -P ~/raw_fonts https://github.com/billryan/algorithm-exercise/files/279471/arial.zip
47-
- echo "install fonts Noto Sans CJK SC for Simplified Chinese"
48-
- wget -P ~/raw_fonts https://noto-website-2.storage.googleapis.com/pkgs/NotoSansCJKsc-hinted.zip
49-
- cd ~/raw_fonts
50-
# - unzip -o NotoSans-unhinted.zip
51-
# - unzip -o migu-1m-20150712.zip
52-
- unzip -o arial.zip
53-
- mv -t ~/.fonts/arial Arial*ttf
54-
- unzip -o NotoSansCJKsc-hinted.zip
55-
# discard other fonts since fontconfig 2.11 cannot identify it
56-
- mv -t ~/.fonts/noto *-DemiLight.otf *-Bold.otf *-Black.otf
31+
- sed '/\(en\/\)/! d' LANGS.md.bak > LANGS.md
32+
- mv -t ~/.fonts/noto ~/raw_fonts/NotoSans-unhinted/*-Regular.ttf ~/raw_fonts/NotoSans-unhinted/*-Bold.ttf ~/raw_fonts/NotoSans-unhinted/*-Black.ttf
5733
- sudo fc-cache -f -v
58-
- cd ~/algorithm-exercise/
59-
- sed '/\(en\/\)/! d' LANGS_bak.md > LANGS.md
60-
#- gitbook build ./
61-
- gitbook pdf ./
62-
- gitbook epub ./
63-
- gitbook mobi ./
34+
- gitbook pdf .
35+
- gitbook epub .
36+
- gitbook mobi .
37+
- rm ~/.fonts/noto/*.ttf
6438

65-
- echo "build Simplified Chinese ebook"
66-
- sed '/\(zh-hans\/\)/! d' LANGS_bak.md > LANGS.md
67-
- cd ~/algorithm-exercise/
68-
#- gitbook build ./
69-
- gitbook pdf ./
70-
- gitbook epub ./
71-
- gitbook mobi ./
72-
# clear CJK fonts(CJK fonts suffer in fontconfig :(
39+
- sed '/\(zh-hans\/\)/! d' LANGS.md.bak > LANGS.md
40+
- mv -t ~/.fonts/noto ~/raw_fonts/NotoSansCJKsc-hinted/*-DemiLight.otf ~/raw_fonts/NotoSansCJKsc-hinted/*-Bold.otf ~/raw_fonts/NotoSansCJKsc-hinted/*-Black.otf
41+
- sudo fc-cache -f -v
42+
- gitbook pdf .
43+
- gitbook epub .
44+
- gitbook mobi .
7345
- rm ~/.fonts/noto/*.otf
7446

75-
- echo "build Traditional Chinese ebook"
76-
- sed '/\(zh-tw\/\)/! d' LANGS_bak.md > LANGS.md
77-
- echo "install fonts Noto Sans CJK TC for Traditional Chinese"
78-
- wget -P ~/raw_fonts https://noto-website-2.storage.googleapis.com/pkgs/NotoSansCJKtc-hinted.zip
79-
- cd ~/raw_fonts
80-
- unzip -o NotoSansCJKtc-hinted.zip
81-
- mv -t ~/.fonts/noto *-DemiLight.otf *-Bold.otf *-Black.otf
47+
- sed '/\(zh-tw\/\)/! d' LANGS.md.bak > LANGS.md
48+
- mv -t ~/.fonts/noto ~/raw_fonts/NotoSansCJKtc-hinted/*-DemiLight.otf ~/raw_fonts/NotoSansCJKtc-hinted/*-Bold.otf ~/raw_fonts/NotoSansCJKtc-hinted/*-Black.otf
8249
- sudo fc-cache -f -v
83-
- cd ~/algorithm-exercise/
84-
#- gitbook build ./
85-
- gitbook pdf ./
86-
- gitbook epub ./
87-
- gitbook mobi ./
50+
- gitbook pdf .
51+
- gitbook epub .
52+
- gitbook mobi .
53+
54+
- cp LANGS.md.bak LANGS.md
55+
- gitbook build .
56+
57+
before_deploy:
58+
- tar czvf book_html.tar.gz _book/
59+
60+
deploy:
61+
- provider: pages
62+
skip-cleanup: true
63+
github-token:
64+
secure: B/dqY0sC9I0Uu5o3HVHouX/mfLTUH/dt16IsBdm+sZQW+/YeTUTGwpx+Vl5lXpMhUoxrh60Qxt0KbnqvPqAxsPXGMH2Mhl1E5lgvMYViOGQyx9JJuuba+GWOzD+r2+XOUsqBzOCUhvC7iZbuGiWYvV2+4noAmAoKa1pO1j2yxiI=
65+
keep-history: false
66+
local-dir: _book
67+
on:
68+
branch: master
69+
target-branch: gh-pages
8870

8971
after_success:
90-
- echo "rename ebook"
91-
- cd ~/algorithm-exercise
92-
- mv *.pdf *.epub *.mobi ~/upload
93-
- cd ~/upload
94-
- sh ~/rename_ebook.sh
9572
- ls -lh
96-
# upload to GitHub and Qiniu
97-
- cd ~/algorithm-exercise
98-
- git remote add github_bak git@github.com:sign4bill/algorithm-exercise.git
99-
#- git push -u github_bak HEAD:master --force
100-
- git checkout --orphan deploy
101-
- mkdir -p {epub,pdf,mobi}
102-
- cp ~/upload/*.epub epub
103-
- cp ~/upload/*.pdf pdf
104-
- cp ~/upload/*.mobi mobi
105-
- git add epub pdf mobi
106-
- git commit -m "Updated $(date)"
107-
- git push -u github_bak deploy --force
108-
- echo "upload to Qiniu CDN for China Mainland"
109-
- ~/qrsync ~/qiniu_sync.json
110-
111-
# blacklist
112-
branches:
113-
except:
114-
- deploy
11573

116-
# whitelist
11774
branches:
11875
only:
119-
- master
120-
- test
76+
- master

CNAME

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
algorithm.yuanbin.me

README.md

+14-83
Original file line numberDiff line numberDiff line change
@@ -4,105 +4,36 @@
44
[![Slack Status](https://slackin4ds-algo.herokuapp.com/badge.svg)](https://slackin4ds-algo.herokuapp.com/)
55
[![Chat on Slack](https://img.shields.io/badge/chat-on_slack-orange.svg)](https://ds-algo.slack.com/)
66

7-
- English via [Data Structure and Algorithm notes](http://algorithm.yuanbin.me/en/index.html)
8-
- 简体中文请戳 [数据结构与算法/leetcode/lintcode题解](http://algorithm.yuanbin.me/zh-hans/index.html)
9-
- 繁體中文請瀏覽 [資料結構與演算法/leetcode/lintcode題解](http://algorithm.yuanbin.me/zh-tw/index.html)
7+
This book is some notes on learning data structure and algorithm. It was written in Simplified Chinese but other languages such as English and Traditional Chinese are work in progress.
108

11-
## Introduction
9+
- [English](https://algorithm.yuanbin.me/en/), seldom updated
10+
- [简体中文](https://algorithm.yuanbin.me/zh-hans/), frequently updated
11+
- [繁體中文](https://algorithm.yuanbin.me/zh-tw/), seldom updated
1212

13-
This work is some notes of learning and practicing data structures and algorithm.
13+
## Introduction
1414

15-
1. Part I is some brief introduction of basic data structures and algorithm, such as, linked lists, stack, queues, trees, sorting and etc.
15+
1. Part I is some brief introduction of basic data structures and algorithm, such as linked lists, stack, queues, trees, sorting.
1616
2. Part II is the analysis and summary of programming problems, and most of the programming problems come from <https://leetcode.com/>, <http://www.lintcode.com/>, <http://www.geeksforgeeks.org/>, <http://hihocoder.com/>, <https://www.topcoder.com/>.
1717
3. Part III is the appendix of resume and other supplements.
1818

19-
This project is hosted on <https://github.com/billryan/algorithm-exercise> and rendered by [Gitbook](https://www.gitbook.com/book/yuanbin/algorithm/details). You can star the repository on the GitHub to keep track of updates. Another choice is to subscribe channel `#github_commit` via Slack <https://ds-algo.slack.com/messages/github_commit/>. ~~RSS feed is under development.~~
19+
This project is hosted on <https://github.com/billryan/algorithm-exercise> and rendered by [GitBook](https://www.gitbook.com/book/yuanbin/algorithm/details). You can star the repository on the GitHub to keep track of updates. Another choice is to subscribe channel `#github_commit` via Slack <https://ds-algo.slack.com/messages/github_commit/>.
2020

21-
Feel free to access <http://slackin4ds-algo.herokuapp.com> for Slack invite automation.
21+
Feel free to access <http://slackin4ds-algo.herokuapp.com> with Slack invite automation.
2222

2323
You can view/search this document online or offline, feel free to read it. :)
2424

25-
- Online(Rendered by Gitbook): <http://algorithm.yuanbin.me>
26-
- Offline(Compiled by Gitbook and Travis-CI):
27-
1. EPUB: [GitHub](https://github.com/sign4bill/algorithm-exercise/tree/deploy/epub), [Gitbook](https://www.gitbook.com/download/epub/book/yuanbin/algorithm), [七牛 CDN(中国大陆用户适用)](http://7xojrx.com1.z0.glb.clouddn.com/docs/algorithm-exercise/index.html) - Recommended for iPhone/iPad/MAC
28-
2. PDF: [GitHub](https://github.com/sign4bill/algorithm-exercise/tree/deploy/pdf), [Gitbook](https://www.gitbook.com/download/pdf/book/yuanbin/algorithm), [七牛 CDN(中国大陆用户适用)](http://7xojrx.com1.z0.glb.clouddn.com/docs/algorithm-exercise/index.html) - Recommended for Desktop
29-
3. MOBI: [GitHub](https://github.com/sign4bill/algorithm-exercise/tree/deploy/mobi), [Gitbook](https://www.gitbook.com/download/mobi/book/yuanbin/algorithm), [七牛 CDN(中国大陆用户适用)](http://7xojrx.com1.z0.glb.clouddn.com/docs/algorithm-exercise/index.html) - Recommended for Kindle
30-
- Site Search via Google: `keywords site:algorithm.yuanbin.me`
31-
- Site Search via Swiftype: Click `Search this site` on the right bottom of webpages
25+
- Online(Rendered by GitBook): <https://algorithm.yuanbin.me>
26+
- Site Search via Google: `keywords site:algorithm.yuanbin.me`
27+
- Site Search via Algolia: Click `Type to search` on the top left corner of webpages
28+
- Offline(Compiled by GitBook on Travis-CI): ePub, PDF, MOBI
3229

3330
## License
3431

3532
This work is licensed under the **Creative Commons Attribution-ShareAlike 4.0 International License**. To view a copy of this license, please visit <http://creativecommons.org/licenses/by-sa/4.0/>
3633

37-
## Contribution
38-
39-
- [English](http://algorithm.yuanbin.me/en/index.html) is maintained by [@billryan](https://github.com/billryan)
40-
- [简体中文](http://algorithm.yuanbin.zh-hans/index.html) is maintained by [@billryan](https://github.com/billryan), [@Shaunwei](https://github.com/Shaunwei)
41-
- [繁體中文](http://algorithm.yuanbin.me/zh-tw/index.html) is maintained by [@CrossLuna](https://github.com/CrossLuna)
42-
43-
Other contributors can be found in [Contributors to algorithm-exercise](https://github.com/billryan/algorithm-exercise/graphs/contributors)
44-
45-
### Donation
46-
47-
本项目接受捐赠,形式不限,可以买书,可以寄明信片,还可以赠送七牛流量券,也可以金额打赏 :)
48-
49-
#### 邮寄明信片
50-
51-
@billryan 喜欢收集各种明信片,来者不拒~ 邮寄的话可以邮寄至 `上海市闵行区上海交通大学闵行校区电院群楼5号楼307`,收件人:`袁斌`
52-
53-
#### 送书
54-
55-
除了邮寄明信片,你还可以买本书送给各位贡献者,@billryan 的地址见上节。
56-
57-
#### 支付宝
58-
59-
![支付宝打赏](./shared-files/images/alipay_billryan_qr15x15.jpg)
60-
61-
账户名:yuanbin2014(at)gmail.com 金额随意
62-
63-
#### Wechat
64-
65-
![Red Packet](./shared-files/images/wechat_billryan_qr15x15.jpg)
66-
67-
金额随意
68-
69-
#### PayPal
70-
71-
账户名:yuanbin2014(at)gmail.com 金额随意,付款时选择 friends and family
72-
73-
隐私考虑,以下名单隐去了部分个人信息,有些名单若没来得及添加,可私下联系我加上,有些信息和金额因为时间久远可能有误,欢迎指正。
74-
75-
- 2015-09-16 支付宝 `taoli***@gmail.com` 20
76-
- 2015-10-30 支付宝 `张亚*` 6.66
77-
- 2015-11-19 支付宝 `wen***@126.com` 10
78-
- 2015-12-25 支付宝 `石*` 50
79-
- 2016-01-05 支付宝 `she***@163.com` 10
80-
- 2016-01-24 支付宝 `187****2296` 20
81-
- 2016-01-15 支付宝 `136****0794` 20
82-
- 2016-03-08 支付宝 `don***@163.com` 5
83-
- 2016-03-21 支付宝 `129***@qq.com` 50
84-
- 2016-07-31 支付宝 `130****9675` 5
85-
- 2016-08-16 PayPal `Tong W***` 20 $
86-
- 2016-08-21 支付宝 `ee.***@gmail.com` 6.66
87-
- 2016-10-09 支付宝 `abc***@126.com` 6.66
88-
- 2016-09-01 明信片 `liaowen***@163.com`
89-
- 2016-10-19 微信 6.66
90-
- 2016-10-13 支付宝 `182****9133` 5
91-
- 2016-11-17 支付宝 `tf.***@gmail.com` 10.24
92-
- 2016-11-19 支付宝 `jat***@163.com` 20
93-
- 2016-11-20 支付宝 `bao***@163.com` 10
94-
- 2017-01-01 明信片 Berkeley CA USA
95-
- 2017-01-09 微信 20
96-
- 2017-01-20 支付宝 `xin***@sina.com` 10
97-
98-
所得捐款用于七牛 CDN 流量付费/激励 Contributors 写出更好的内容/购买书籍/西瓜/饮料
99-
10034
## To Do
10135

102-
- [ ] add multiple languages support, currently 繁體中文, 简体中文 are available
103-
- [x] explore nice writing style
104-
- [x] add implementations of `Python`, `C++`, `Java` code
36+
- [ ] add multiple languages support
37+
- [ ] add implementations of `Python`, `C++` and `Java` code
10538
- [x] add time and space complexity analysis
106-
- [x] summary of basic data structure and algorithm
107-
- [x] add CSS for online website <http://algorithm.yuanbin.me>
10839
- [x] add proper Chinese fonts for PDF output

id_rsa.enc

-3.17 KB
Binary file not shown.

scripts/leetcode.py

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
5+
from selenium import webdriver
6+
7+
8+
class Leetcode(object):
9+
10+
def __init__(self):
11+
chrome_options = webdriver.ChromeOptions()
12+
chrome_options.add_argument('--headless')
13+
chrome_options.add_argument('--disable-gpu')
14+
self.driver = webdriver.Chrome(chrome_options=chrome_options)
15+
16+
def open_url(self, url):
17+
self.url = url
18+
print('open URL: {}'.format(url))
19+
self.driver.get(url)
20+
21+
def teardown(self):
22+
self.driver.close()
23+
24+
def get_title(self):
25+
print('get title...')
26+
raw_title = self.driver.title
27+
title = raw_title[:-len(' - LeetCode')].strip()
28+
return title
29+
30+
def get_description(self):
31+
print('get description...')
32+
elem = self.driver.find_element_by_class_name('question-description')
33+
return elem.get_attribute('innerHTML')
34+
35+
def get_difficulty(self):
36+
print('get difficulty...')
37+
elem = self.driver.find_element_by_class_name('difficulty-label')
38+
return elem.get_attribute('innerHTML')
39+
40+
def get_tags(self):
41+
print('get tags...')
42+
tags_id = self.driver.find_element_by_id('tags-topics')
43+
tags_id_a = tags_id.find_elements_by_tag_name('a')
44+
tags = []
45+
for i in tags_id_a:
46+
tag = i.get_attribute('innerHTML')
47+
tags.append(tag)
48+
return tags
49+
50+
def _clean_url(self, url):
51+
new_url = ['https:/', 'leetcode.com', 'problems']
52+
problem_slug = url[len('https://'):].strip('/').split('/')[2]
53+
new_url.append(problem_slug)
54+
return '/'.join(new_url)
55+
56+
def get_problem_all(self, url):
57+
"""获取所有细节"""
58+
print('get all the problem detail...')
59+
self.open_url(url)
60+
title = self.get_title()
61+
difficulty = self.get_difficulty()
62+
tags = self.get_tags()
63+
description = self.get_description()
64+
problem = {
65+
'title': title,
66+
'difficulty': difficulty,
67+
'tags': tags,
68+
'description': description,
69+
'url': self._clean_url(url)
70+
}
71+
self.teardown()
72+
return problem
73+
74+
75+
if __name__ == '__main__':
76+
url = 'https://leetcode.com/problems/palindrome-number'
77+
leetcode = Leetcode()
78+
print(leetcode.get_problem_all(url))

0 commit comments

Comments
 (0)