├── refs
└── add.bib
├── .Rbuildignore
├── .Rproj.user
├── shared
│ └── notebooks
│ │ ├── patch-chunk-names
│ │ ├── C7BDE1B7-deep_learn
│ │ └── 1
│ │ │ └── 4A13D08206E9C08B
│ │ │ └── chunks.json
│ │ └── paths
└── 4A13D082
│ ├── saved_source_markers
│ ├── pcs
│ ├── source-pane.pper
│ ├── workbench-pane.pper
│ ├── files-pane.pper
│ └── windowlayoutstate.pper
│ ├── sources
│ └── prop
│ │ ├── 7D30E6E5
│ │ ├── 6B4EB6C4
│ │ ├── 800F1B8A
│ │ ├── A6145623
│ │ └── INDEX
│ ├── rmd-outputs
│ └── persistent-state
├── code
├── build.R
├── build-model-notes.R
├── clean.R
├── copy-md.R
├── push.R
├── build-readme.R
└── build-jupyter-notebook.R
├── .gitignore
├── figs
├── cow1.png
├── cow2.png
├── dcss1.png
├── dcss2.png
├── dp_1.png
├── hdck.png
├── jxfg.png
├── jzzl.png
├── khao.png
├── ljzh3.png
├── lxjz.png
├── lxjz2.png
├── tx_1.png
├── tyyx2.png
├── xztx.png
├── zuida.png
├── 不同路径.png
├── 买卖股票1.png
├── 买卖股票2.png
├── 买卖股票3.png
├── 买卖股票4.png
├── 买卖股票5.png
├── 买卖股票6.png
├── 买卖股票7.png
├── 买卖股票8.png
├── 买卖股票9.png
├── 公共祖先.png
├── 动态规划.png
├── 左叶子之和.png
├── 所有路径.png
├── 接雨水1.png
├── 爬楼梯.png
├── 盛水容器1.png
├── 盛水容器2.png
├── 路径总和.png
├── 跳跃游戏.png
├── array_1.png
├── deepth.png
├── dhhmzh.png
├── djjs3-1.png
├── djjs3-2.png
├── djjs3-3.png
├── lbggjd.png
├── ssewjz1.png
├── ssewjz2.png
├── 买卖股票10.png
├── 买卖股票11.png
├── 买卖股票12.png
├── 最长回文字符串.png
├── 盛水最多的容器.png
├── base_kg_1.png
├── base_kg_2.jpg
├── base_kg_3.png
├── jieyushui.png
├── lianbiao1.png
├── lianbiao2.png
├── lianbiao_1.png
├── lianbiao_2.png
├── lianbiao_3.png
├── 动态规划问题解题思路.png
├── 最短路径和的问题.png
├── cengcibianli.png
├── duichentree.png
├── fanzhuantree.png
├── lujingzonghe.png
├── pinghengtree.png
├── wanquan_tree.png
├── zuidasquare.png
├── 时间复杂度与空间复杂度.jpg
├── gonggongzixulie.jpg
├── xaingtongtree.png
├── huanxinglianbiao.png
└── youxushuzuzhuantree.png
├── analysis
├── summary.Rmd
├── libs
│ ├── gitbook-2.6.7
│ │ ├── css
│ │ │ ├── fontawesome
│ │ │ │ └── fontawesome-webfont.ttf
│ │ │ ├── plugin-clipboard.css
│ │ │ ├── plugin-table.css
│ │ │ ├── plugin-search.css
│ │ │ ├── plugin-bookdown.css
│ │ │ └── plugin-fontsettings.css
│ │ └── js
│ │ │ ├── plugin-clipboard.js
│ │ │ ├── jquery.highlight.js
│ │ │ ├── plugin-sharing.js
│ │ │ ├── plugin-fontsettings.js
│ │ │ ├── plugin-search.js
│ │ │ ├── plugin-bookdown.js
│ │ │ └── clipboard.min.js
│ └── header-attrs-2.2
│ │ └── header-attrs.js
├── Monotone_stack.Rmd
├── leetcode.Rmd
├── time_complexity.Rmd
├── jiano.Rmd
├── sort.py
├── base_kg.Rmd
├── k-num-sum.Rmd
├── array.Rmd
├── sort.Rmd
├── string.Rmd
└── huisu.Rmd
├── libs
├── gitbook-2.6.7
│ ├── css
│ │ ├── fontawesome
│ │ │ └── fontawesome-webfont.ttf
│ │ ├── plugin-clipboard.css
│ │ ├── plugin-table.css
│ │ ├── plugin-search.css
│ │ ├── plugin-bookdown.css
│ │ └── plugin-fontsettings.css
│ └── js
│ │ ├── plugin-clipboard.js
│ │ ├── jquery.highlight.js
│ │ ├── plugin-sharing.js
│ │ ├── plugin-fontsettings.js
│ │ ├── plugin-search.js
│ │ ├── plugin-bookdown.js
│ │ └── clipboard.min.js
├── header-attrs-2.2
│ └── header-attrs.js
└── pagedtable-1.1
│ └── css
│ └── pagedtable.css
├── le_leetcode.Rproj
├── dandiao_stack.Rmd
├── cxmsbd_py.Rmd
├── slide_window.Rmd
├── Makefile
├── queue_and_stack.Rmd
├── README.md
├── py_base.Rmd
└── 栈和队列.html
/refs/add.bib:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.Rbuildignore:
--------------------------------------------------------------------------------
1 | ^Makefile$
2 |
--------------------------------------------------------------------------------
/.Rproj.user/shared/notebooks/patch-chunk-names:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/code/build.R:
--------------------------------------------------------------------------------
1 | rmarkdown::render("leetcode.Rmd")
2 |
3 |
--------------------------------------------------------------------------------
/.Rproj.user/4A13D082/saved_source_markers:
--------------------------------------------------------------------------------
1 | {"active_set":"","sets":[]}
--------------------------------------------------------------------------------
/.Rproj.user/4A13D082/pcs/source-pane.pper:
--------------------------------------------------------------------------------
1 | {
2 | "activeTab": 0
3 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .Rproj.user
2 | .Rhistory
3 | .RData
4 | .Ruserdata
5 |
--------------------------------------------------------------------------------
/code/build-model-notes.R:
--------------------------------------------------------------------------------
1 | #rmarkdown::render("model_notes.Rmd")
2 |
3 |
--------------------------------------------------------------------------------
/figs/cow1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/cow1.png
--------------------------------------------------------------------------------
/figs/cow2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/cow2.png
--------------------------------------------------------------------------------
/figs/dcss1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/dcss1.png
--------------------------------------------------------------------------------
/figs/dcss2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/dcss2.png
--------------------------------------------------------------------------------
/figs/dp_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/dp_1.png
--------------------------------------------------------------------------------
/figs/hdck.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/hdck.png
--------------------------------------------------------------------------------
/figs/jxfg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/jxfg.png
--------------------------------------------------------------------------------
/figs/jzzl.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/jzzl.png
--------------------------------------------------------------------------------
/figs/khao.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/khao.png
--------------------------------------------------------------------------------
/figs/ljzh3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/ljzh3.png
--------------------------------------------------------------------------------
/figs/lxjz.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/lxjz.png
--------------------------------------------------------------------------------
/figs/lxjz2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/lxjz2.png
--------------------------------------------------------------------------------
/figs/tx_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/tx_1.png
--------------------------------------------------------------------------------
/figs/tyyx2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/tyyx2.png
--------------------------------------------------------------------------------
/figs/xztx.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/xztx.png
--------------------------------------------------------------------------------
/figs/zuida.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/zuida.png
--------------------------------------------------------------------------------
/figs/不同路径.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/不同路径.png
--------------------------------------------------------------------------------
/figs/买卖股票1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/买卖股票1.png
--------------------------------------------------------------------------------
/figs/买卖股票2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/买卖股票2.png
--------------------------------------------------------------------------------
/figs/买卖股票3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/买卖股票3.png
--------------------------------------------------------------------------------
/figs/买卖股票4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/买卖股票4.png
--------------------------------------------------------------------------------
/figs/买卖股票5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/买卖股票5.png
--------------------------------------------------------------------------------
/figs/买卖股票6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/买卖股票6.png
--------------------------------------------------------------------------------
/figs/买卖股票7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/买卖股票7.png
--------------------------------------------------------------------------------
/figs/买卖股票8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/买卖股票8.png
--------------------------------------------------------------------------------
/figs/买卖股票9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/买卖股票9.png
--------------------------------------------------------------------------------
/figs/公共祖先.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/公共祖先.png
--------------------------------------------------------------------------------
/figs/动态规划.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/动态规划.png
--------------------------------------------------------------------------------
/figs/左叶子之和.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/左叶子之和.png
--------------------------------------------------------------------------------
/figs/所有路径.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/所有路径.png
--------------------------------------------------------------------------------
/figs/接雨水1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/接雨水1.png
--------------------------------------------------------------------------------
/figs/爬楼梯.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/爬楼梯.png
--------------------------------------------------------------------------------
/figs/盛水容器1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/盛水容器1.png
--------------------------------------------------------------------------------
/figs/盛水容器2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/盛水容器2.png
--------------------------------------------------------------------------------
/figs/路径总和.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/路径总和.png
--------------------------------------------------------------------------------
/figs/跳跃游戏.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/跳跃游戏.png
--------------------------------------------------------------------------------
/figs/array_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/array_1.png
--------------------------------------------------------------------------------
/figs/deepth.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/deepth.png
--------------------------------------------------------------------------------
/figs/dhhmzh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/dhhmzh.png
--------------------------------------------------------------------------------
/figs/djjs3-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/djjs3-1.png
--------------------------------------------------------------------------------
/figs/djjs3-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/djjs3-2.png
--------------------------------------------------------------------------------
/figs/djjs3-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/djjs3-3.png
--------------------------------------------------------------------------------
/figs/lbggjd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/lbggjd.png
--------------------------------------------------------------------------------
/figs/ssewjz1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/ssewjz1.png
--------------------------------------------------------------------------------
/figs/ssewjz2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/ssewjz2.png
--------------------------------------------------------------------------------
/figs/买卖股票10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/买卖股票10.png
--------------------------------------------------------------------------------
/figs/买卖股票11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/买卖股票11.png
--------------------------------------------------------------------------------
/figs/买卖股票12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/买卖股票12.png
--------------------------------------------------------------------------------
/figs/最长回文字符串.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/最长回文字符串.png
--------------------------------------------------------------------------------
/figs/盛水最多的容器.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/盛水最多的容器.png
--------------------------------------------------------------------------------
/figs/base_kg_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/base_kg_1.png
--------------------------------------------------------------------------------
/figs/base_kg_2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/base_kg_2.jpg
--------------------------------------------------------------------------------
/figs/base_kg_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/base_kg_3.png
--------------------------------------------------------------------------------
/figs/jieyushui.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/jieyushui.png
--------------------------------------------------------------------------------
/figs/lianbiao1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/lianbiao1.png
--------------------------------------------------------------------------------
/figs/lianbiao2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/lianbiao2.png
--------------------------------------------------------------------------------
/figs/lianbiao_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/lianbiao_1.png
--------------------------------------------------------------------------------
/figs/lianbiao_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/lianbiao_2.png
--------------------------------------------------------------------------------
/figs/lianbiao_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/lianbiao_3.png
--------------------------------------------------------------------------------
/figs/动态规划问题解题思路.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/动态规划问题解题思路.png
--------------------------------------------------------------------------------
/figs/最短路径和的问题.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/最短路径和的问题.png
--------------------------------------------------------------------------------
/figs/cengcibianli.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/cengcibianli.png
--------------------------------------------------------------------------------
/figs/duichentree.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/duichentree.png
--------------------------------------------------------------------------------
/figs/fanzhuantree.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/fanzhuantree.png
--------------------------------------------------------------------------------
/figs/lujingzonghe.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/lujingzonghe.png
--------------------------------------------------------------------------------
/figs/pinghengtree.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/pinghengtree.png
--------------------------------------------------------------------------------
/figs/wanquan_tree.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/wanquan_tree.png
--------------------------------------------------------------------------------
/figs/zuidasquare.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/zuidasquare.png
--------------------------------------------------------------------------------
/figs/时间复杂度与空间复杂度.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/时间复杂度与空间复杂度.jpg
--------------------------------------------------------------------------------
/.Rproj.user/4A13D082/sources/prop/7D30E6E5:
--------------------------------------------------------------------------------
1 | {
2 | "cursorPosition": "10,3",
3 | "scrollLine": "0"
4 | }
--------------------------------------------------------------------------------
/figs/gonggongzixulie.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/gonggongzixulie.jpg
--------------------------------------------------------------------------------
/figs/xaingtongtree.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/xaingtongtree.png
--------------------------------------------------------------------------------
/.Rproj.user/4A13D082/pcs/workbench-pane.pper:
--------------------------------------------------------------------------------
1 | {
2 | "TabSet1": 0,
3 | "TabSet2": 0,
4 | "TabZoom": {}
5 | }
--------------------------------------------------------------------------------
/figs/huanxinglianbiao.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/huanxinglianbiao.png
--------------------------------------------------------------------------------
/figs/youxushuzuzhuantree.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/figs/youxushuzuzhuantree.png
--------------------------------------------------------------------------------
/.Rproj.user/shared/notebooks/C7BDE1B7-deep_learn/1/4A13D08206E9C08B/chunks.json:
--------------------------------------------------------------------------------
1 | {"chunk_definitions":[],"doc_write_time":1585570632}
--------------------------------------------------------------------------------
/analysis/summary.Rmd:
--------------------------------------------------------------------------------
1 | ## 算法思想小结
2 |
3 |
4 | ## 分治之思想
5 |
6 | 把任务分解为子任务,子任务的合并结果就是主任务的解
7 |
8 | 典型:
9 |
10 | 快速排序
11 | 二分法查找
--------------------------------------------------------------------------------
/code/clean.R:
--------------------------------------------------------------------------------
1 | library(tidyverse)
2 | fs::dir_ls(".", regexp = "\\.md$") %>%
3 | str_subset("README|LICENSE", negate = TRUE) %>%
4 | map(file.remove)
5 |
--------------------------------------------------------------------------------
/code/copy-md.R:
--------------------------------------------------------------------------------
1 | rmarkdown::render("commit.Rmd")
2 | library(magrittr)
3 | readr::read_lines("commit.md") %>%
4 | clipr::write_clip(allow_non_interactive = TRUE)
5 |
--------------------------------------------------------------------------------
/code/push.R:
--------------------------------------------------------------------------------
1 | git2r::add(path = ".")
2 | git2r::commit(message = "build gitbook")
3 | git2r::push(name = 'origin', refspec = "refs/heads/master", cred = git2r::cred_token())
4 |
--------------------------------------------------------------------------------
/libs/gitbook-2.6.7/css/fontawesome/fontawesome-webfont.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/libs/gitbook-2.6.7/css/fontawesome/fontawesome-webfont.ttf
--------------------------------------------------------------------------------
/analysis/libs/gitbook-2.6.7/css/fontawesome/fontawesome-webfont.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gaowenxin95/leetcode-cookbook/HEAD/analysis/libs/gitbook-2.6.7/css/fontawesome/fontawesome-webfont.ttf
--------------------------------------------------------------------------------
/.Rproj.user/4A13D082/sources/prop/6B4EB6C4:
--------------------------------------------------------------------------------
1 | {
2 | "cursorPosition": "3,0",
3 | "docOutlineSize": "40",
4 | "docOutlineVisible": "1",
5 | "scrollLine": "0",
6 | "tempName": "Untitled2"
7 | }
--------------------------------------------------------------------------------
/.Rproj.user/4A13D082/sources/prop/800F1B8A:
--------------------------------------------------------------------------------
1 | {
2 | "tempName": "Untitled2",
3 | "cursorPosition": "13,2",
4 | "scrollLine": "0",
5 | "docOutlineSize": "40",
6 | "docOutlineVisible": "1"
7 | }
--------------------------------------------------------------------------------
/.Rproj.user/4A13D082/sources/prop/A6145623:
--------------------------------------------------------------------------------
1 | {
2 | "tempName": "Untitled2",
3 | "cursorPosition": "1,15",
4 | "scrollLine": "0",
5 | "docOutlineSize": "40",
6 | "docOutlineVisible": "1"
7 | }
--------------------------------------------------------------------------------
/analysis/Monotone_stack.Rmd:
--------------------------------------------------------------------------------
1 | ---
2 | title : 单调栈专题
3 | author: 高文欣
4 | date: "`r Sys.Date()`"
5 | output: bookdown::gitbook
6 | bibliography: refs/add.bib
7 | ---
8 |
9 | # 单调栈
10 |
11 | # 定义
12 |
13 |
--------------------------------------------------------------------------------
/.Rproj.user/4A13D082/pcs/files-pane.pper:
--------------------------------------------------------------------------------
1 | {
2 | "sortOrder": [
3 | {
4 | "columnIndex": 2,
5 | "ascending": true
6 | }
7 | ],
8 | "path": "A:/Gaowenxin_notes/leetcode/leetcode-cookbook"
9 | }
--------------------------------------------------------------------------------
/code/build-readme.R:
--------------------------------------------------------------------------------
1 | rmarkdown::render("README.Rmd")
2 | git2r::add(path = "*README*")
3 | git2r::add(path = "*readme*")
4 | git2r::commit(message = "update readme")
5 | git2r::push(name = 'origin', refspec = "refs/heads/master", cred = git2r::cred_token())
6 |
--------------------------------------------------------------------------------
/code/build-jupyter-notebook.R:
--------------------------------------------------------------------------------
1 | library(tidyverse)
2 | # read_lines("notebook.md") %>%
3 | # str_replace("^## \\d+\\. ", "### ") %>%
4 | # write_lines("notebook.md")
5 | # read_lines("Ex50.md") %>%
6 | # str_replace("^## ", "# ") %>%
7 | # write_lines("Ex50.md")
8 |
--------------------------------------------------------------------------------
/analysis/leetcode.Rmd:
--------------------------------------------------------------------------------
1 | ---
2 | title : 剑指offer
3 | author: 高文欣
4 | date: "`r Sys.Date()`"
5 | output: bookdown::gitbook
6 | bibliography: refs/add.bib
7 | ---
8 |
9 | # 数据结构算法
10 |
11 | 每日一问:你的能力够彪悍了嘛?
12 |
13 | ## 二叉树问题
14 | ```{r child='}
15 |
16 | ```
17 |
18 |
--------------------------------------------------------------------------------
/le_leetcode.Rproj:
--------------------------------------------------------------------------------
1 | Version: 1.0
2 |
3 | RestoreWorkspace: Default
4 | SaveWorkspace: Default
5 | AlwaysSaveHistory: Default
6 |
7 | EnableCodeIndexing: Yes
8 | UseSpacesForTab: Yes
9 | NumSpacesForTab: 2
10 | Encoding: UTF-8
11 |
12 | RnwWeave: knitr
13 | LaTeX: XeLaTeX
14 |
15 | BuildType: Makefile
16 |
--------------------------------------------------------------------------------
/dandiao_stack.Rmd:
--------------------------------------------------------------------------------
1 | ---
2 | title : 单调栈
3 | author: 高文欣
4 | date: "`r Sys.Date()`"
5 | output: bookdown::gitbook
6 | bibliography: refs/add.bib
7 | ---
8 |
9 | # 单调栈
10 |
11 | ## 定义
12 |
13 | 单调栈是指栈内元素是具有有单调性的栈,单调栈在入栈的时候,需要将待入栈的元素和栈顶元素进行对比,看待加入栈的元素入栈后是否会破坏栈的单调性,如果不会,直接入栈;否则一直弹出到满足条件为止。
14 |
15 | 单调递增栈:从栈顶到栈底数据从小到大
16 | 单调递减栈:从栈顶到栈底数据从大到小
17 |
18 |
--------------------------------------------------------------------------------
/.Rproj.user/4A13D082/pcs/windowlayoutstate.pper:
--------------------------------------------------------------------------------
1 | {
2 | "left": {
3 | "splitterpos": 238,
4 | "topwindowstate": "NORMAL",
5 | "panelheight": 631,
6 | "windowheight": 669
7 | },
8 | "right": {
9 | "splitterpos": 400,
10 | "topwindowstate": "NORMAL",
11 | "panelheight": 631,
12 | "windowheight": 669
13 | }
14 | }
--------------------------------------------------------------------------------
/libs/gitbook-2.6.7/css/plugin-clipboard.css:
--------------------------------------------------------------------------------
1 | div.sourceCode {
2 | position: relative;
3 | }
4 |
5 | .copy-to-clipboard-button {
6 | position: absolute;
7 | right: 0;
8 | top: 0;
9 | visibility: hidden;
10 | }
11 |
12 | .copy-to-clipboard-button:focus {
13 | outline: 0;
14 | }
15 |
16 | div.sourceCode:hover > .copy-to-clipboard-button {
17 | visibility: visible;
18 | }
19 |
--------------------------------------------------------------------------------
/analysis/libs/gitbook-2.6.7/css/plugin-clipboard.css:
--------------------------------------------------------------------------------
1 | div.sourceCode {
2 | position: relative;
3 | }
4 |
5 | .copy-to-clipboard-button {
6 | position: absolute;
7 | right: 0;
8 | top: 0;
9 | visibility: hidden;
10 | }
11 |
12 | .copy-to-clipboard-button:focus {
13 | outline: 0;
14 | }
15 |
16 | div.sourceCode:hover > .copy-to-clipboard-button {
17 | visibility: visible;
18 | }
19 |
--------------------------------------------------------------------------------
/.Rproj.user/4A13D082/rmd-outputs:
--------------------------------------------------------------------------------
1 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/leetcode-hot-100.html
2 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/leetcode-hot-100.html
3 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/leetcode-hot-100.html
4 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/leetcode-hot-100.html
5 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/leetcode-hot-100.html
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/cxmsbd_py.Rmd:
--------------------------------------------------------------------------------
1 | ---
2 | title: "stack_queue"
3 | author: "wenxin Gao"
4 | date: "2020/9/20"
5 | output: html_document
6 | ---
7 |
8 | # 栈和队列
9 |
10 | ## 定义
11 |
12 | **栈**:后进先出(LIFO-last in first out):最后插入的元素最先出来。
13 |
14 | **队列**:先进先出(FIFO-first in first out):最先插入的元素最先出来
15 |
16 | pop和peek都可以返回栈顶元素,时间复杂度是O(1)
17 | stack1.peek() 返回栈顶元素,但不在堆栈中删除它。
18 | Stack2.pop() 返回栈顶元素,并在进程中删除它。
19 |
20 | 栈这里考的辅助栈比较多一点
--------------------------------------------------------------------------------
/slide_window.Rmd:
--------------------------------------------------------------------------------
1 |
2 |
3 | # 滑动窗口
4 |
5 | 模板
6 |
7 | ```r
8 | int left = 0, right = 0;
9 |
10 | while (right < s.size()) {
11 | // 增大窗口
12 | window.add(s[right]);
13 | right++;
14 |
15 | while (window needs shrink) {
16 | // 缩小窗口
17 | window.remove(s[left]);
18 | left++;
19 | }
20 | }
21 | ```
22 |
23 | [labuladong](https://leetcode.cn/problems/find-all-anagrams-in-a-string/solutions/9749/hua-dong-chuang-kou-tong-yong-si-xiang-jie-jue-zi-/)
24 |
--------------------------------------------------------------------------------
/libs/header-attrs-2.2/header-attrs.js:
--------------------------------------------------------------------------------
1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to
2 | // be compatible with the behavior of Pandoc < 2.8).
3 | document.addEventListener('DOMContentLoaded', function(e) {
4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
5 | var i, h, a;
6 | for (i = 0; i < hs.length; i++) {
7 | h = hs[i];
8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
9 | a = h.attributes;
10 | while (a.length > 0) h.removeAttribute(a[0].name);
11 | }
12 | });
13 |
--------------------------------------------------------------------------------
/analysis/libs/header-attrs-2.2/header-attrs.js:
--------------------------------------------------------------------------------
1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to
2 | // be compatible with the behavior of Pandoc < 2.8).
3 | document.addEventListener('DOMContentLoaded', function(e) {
4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
5 | var i, h, a;
6 | for (i = 0; i < hs.length; i++) {
7 | h = hs[i];
8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
9 | a = h.attributes;
10 | while (a.length > 0) h.removeAttribute(a[0].name);
11 | }
12 | });
13 |
--------------------------------------------------------------------------------
/.Rproj.user/4A13D082/persistent-state:
--------------------------------------------------------------------------------
1 | build-last-errors="[]"
2 | build-last-errors-base-dir=""
3 | build-last-outputs="[]"
4 | compile_pdf_state="{\"tab_visible\":false,\"running\":false,\"target_file\":\"\",\"output\":\"\",\"errors\":[]}"
5 | files.monitored-path=""
6 | find-in-files-state="{\"handle\":\"\",\"input\":\"\",\"path\":\"\",\"regex\":false,\"ignoreCase\":false,\"results\":{\"file\":[],\"line\":[],\"lineValue\":[],\"matchOn\":[],\"matchOff\":[],\"replaceMatchOn\":[],\"replaceMatchOff\":[]},\"running\":false,\"replace\":false,\"preview\":false,\"gitFlag\":false,\"replacePattern\":\"\"}"
7 | imageDirtyState="1"
8 | saveActionState="-1"
9 |
--------------------------------------------------------------------------------
/libs/gitbook-2.6.7/css/plugin-table.css:
--------------------------------------------------------------------------------
1 | .book .book-body .page-wrapper .page-inner section.normal table{display:table;width:100%;border-collapse:collapse;border-spacing:0;overflow:auto}.book .book-body .page-wrapper .page-inner section.normal table td,.book .book-body .page-wrapper .page-inner section.normal table th{padding:6px 13px;border:1px solid #ddd}.book .book-body .page-wrapper .page-inner section.normal table tr{background-color:#fff;border-top:1px solid #ccc}.book .book-body .page-wrapper .page-inner section.normal table tr:nth-child(2n){background-color:#f8f8f8}.book .book-body .page-wrapper .page-inner section.normal table th{font-weight:700}
2 |
--------------------------------------------------------------------------------
/analysis/libs/gitbook-2.6.7/css/plugin-table.css:
--------------------------------------------------------------------------------
1 | .book .book-body .page-wrapper .page-inner section.normal table{display:table;width:100%;border-collapse:collapse;border-spacing:0;overflow:auto}.book .book-body .page-wrapper .page-inner section.normal table td,.book .book-body .page-wrapper .page-inner section.normal table th{padding:6px 13px;border:1px solid #ddd}.book .book-body .page-wrapper .page-inner section.normal table tr{background-color:#fff;border-top:1px solid #ccc}.book .book-body .page-wrapper .page-inner section.normal table tr:nth-child(2n){background-color:#f8f8f8}.book .book-body .page-wrapper .page-inner section.normal table th{font-weight:700}
2 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | jupyter:
2 |
3 | jupyter nbconvert --to markdown --output-dir . --NbConvertApp.output_files_dir=libs \
4 | analysis/numpy_irr.ipynb
5 |
6 | jupyter nbconvert --to markdown --output-dir . --NbConvertApp.output_files_dir=libs \
7 | project/which_debts_are_worth_the_bank_s_effort/notebook.ipynb
8 |
9 | Rscript code/build-jupyter-notebook.R
10 |
11 | cookbook:
12 |
13 | Rscript code/build.R
14 |
15 | model:
16 |
17 | Rscript code/build-model-notes.R
18 |
19 | readme:
20 |
21 | Rscript code/build-readme.R
22 |
23 | push:
24 |
25 | Rscript code/push.R
26 |
27 | copy:
28 |
29 | Rscript code/copy-md.R
30 |
31 | clean:
32 |
33 | Rscript code/clean.R
34 |
35 | all: jupyter cookbook clean push
36 |
--------------------------------------------------------------------------------
/analysis/time_complexity.Rmd:
--------------------------------------------------------------------------------
1 | ## 时间复杂度
2 |
3 | 时间复杂度计算问题~
4 |
5 | 在计算时间复杂度时,只需关注循环次数最多的那段代码即可。也就是算法中某条语句的执行次数~
6 |
7 | ### 常见的时间复杂度
8 |
9 | (1)O(1):常量阶,运行时间为常量 #常见输入输出或者赋值语句
10 |
11 | (2)O(logn):对数阶,如二分搜索算法 #这里的log一般以2为底
12 |
13 | (3)O(n):线性阶,如n个数内找最大值 # 一般单层for循环
14 |
15 | (4)O(nlogn):对数阶,如**快速排序算法,归并排序**
16 |
17 | (5)O(n^2):平方阶,如选择排序,冒泡排序 #双层for循环
18 |
19 | (6)O(n^3):立方阶,如两个n阶矩阵的乘法运算
20 |
21 | (7)O(2^n):指数阶,如n个元素集合的所有**子集**的算法
22 |
23 | (8)O(n!):阶乘阶,如n个元素全部排列的算法
24 |
25 | $$\mathrm{O}(1)<\mathrm{O}(\log n)<\mathrm{O}(n)<\mathrm{O}(n \log n)<\mathrm{O}\left(n^{2}\right)<\mathrm{O}\left(n^{3}\right)<\mathrm{O}\left(2^{n}\right)<\mathrm{O}(n !)<\mathrm{O}\left(n^{n}\right)$$
26 |
27 |
28 | 感觉还是需要举个例子
--------------------------------------------------------------------------------
/queue_and_stack.Rmd:
--------------------------------------------------------------------------------
1 | ---
2 | title : 栈和队列
3 | author: 高文欣
4 | date: "`r Sys.Date()`"
5 | output: bookdown::gitbook
6 | bibliography: refs/add.bib
7 | ---
8 |
9 | # 栈和队列
10 |
11 | ## 栈与递归的关系
12 |
13 |
14 | 通常,当在一个函数的运行期间调用另一个函数时,在运行被调用函数之前,系统要做三件事:
15 |
16 |
17 | - 将所有的实参,返回地址等信息调用传递给被调用函数保存;
18 | - 为被调用函数的局部变量分配存储空间;
19 | - 将控制权转移到被调用函数入口;
20 |
21 | 一个递归函数的运行过程类似多个函数的嵌套调用,只是调用函数和被调用函数都是同一个函数,因此,每次调用本身时,就会产生一个调用相关的一个重要概念就是递归函数运行的"层次".假设调用该递归函数的主函数为第0层,则从主函数调用递归函数进入到第一层,从第i层递归调用本函数进入下一层为第i+1层,反之退出第i层递归函数返回上一层为第i-1层;
22 | 为了保证递归函数正确执行,系统需要设立一个"递归工作栈"作为整个递归函数运行期间使用的数据存储区,每一层递归所需信息构成一个工作记录,其中包括所有实参,所有局部变量以及上一层的返回地址.每进入一层递归,就产生一个新的工作记录压入栈顶,每退出一个递归,就从栈顶弹出一个工作记录,则当前执行层的工作记录必须是递归工作栈栈顶的工作记录,此称为"活动记录";[【ChaosHeart】](https://www.jianshu.com/p/0d62fc267520)
23 |
--------------------------------------------------------------------------------
/libs/gitbook-2.6.7/css/plugin-search.css:
--------------------------------------------------------------------------------
1 | .book .book-summary .book-search {
2 | padding: 6px;
3 | background: transparent;
4 | position: absolute;
5 | top: -50px;
6 | left: 0px;
7 | right: 0px;
8 | transition: top 0.5s ease;
9 | }
10 | .book .book-summary .book-search input,
11 | .book .book-summary .book-search input:focus,
12 | .book .book-summary .book-search input:hover {
13 | width: 100%;
14 | background: transparent;
15 | border: 1px solid #ccc;
16 | box-shadow: none;
17 | outline: none;
18 | line-height: 22px;
19 | padding: 7px 4px;
20 | color: inherit;
21 | box-sizing: border-box;
22 | }
23 | .book.with-search .book-summary .book-search {
24 | top: 0px;
25 | }
26 | .book.with-search .book-summary ul.summary {
27 | top: 50px;
28 | }
29 | .with-search .summary li[data-level] a[href*=".html#"] {
30 | display: none;
31 | }
32 |
--------------------------------------------------------------------------------
/analysis/libs/gitbook-2.6.7/css/plugin-search.css:
--------------------------------------------------------------------------------
1 | .book .book-summary .book-search {
2 | padding: 6px;
3 | background: transparent;
4 | position: absolute;
5 | top: -50px;
6 | left: 0px;
7 | right: 0px;
8 | transition: top 0.5s ease;
9 | }
10 | .book .book-summary .book-search input,
11 | .book .book-summary .book-search input:focus,
12 | .book .book-summary .book-search input:hover {
13 | width: 100%;
14 | background: transparent;
15 | border: 1px solid #ccc;
16 | box-shadow: none;
17 | outline: none;
18 | line-height: 22px;
19 | padding: 7px 4px;
20 | color: inherit;
21 | box-sizing: border-box;
22 | }
23 | .book.with-search .book-summary .book-search {
24 | top: 0px;
25 | }
26 | .book.with-search .book-summary ul.summary {
27 | top: 50px;
28 | }
29 | .with-search .summary li[data-level] a[href*=".html#"] {
30 | display: none;
31 | }
32 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # leetcode-cookbook
2 |
3 |
4 | - [二叉树](https://gaowenxin95.github.io/leetcode-cookbook/二叉树专题.html)
5 |
6 | - [动态规划](https://gaowenxin95.github.io/leetcode-cookbook/analysis/动态规划问题.html)
7 |
8 | - [链表](https://gaowenxin95.github.io/leetcode-cookbook/analysis/链表问题.html)
9 |
10 | - [回溯](https://gaowenxin95.github.io/leetcode-cookbook/analysis/回溯专题.html)
11 |
12 | - [贪心](https://gaowenxin95.github.io/leetcode-cookbook/analysis/贪心专题.html)
13 |
14 | - [必会10大排序算法](https://gaowenxin95.github.io/leetcode-cookbook/analysis/十大经典排序.html)
15 |
16 | - [字符串](https://gaowenxin95.github.io/leetcode-cookbook/analysis/字符串专题.html)
17 |
18 | - [数组](https://gaowenxin95.github.io/leetcode-cookbook/analysis/数组专题.html)
19 |
20 | - [剑指offer68道题解](https://gaowenxin95.github.io/leetcode-cookbook/剑指offer题解.html)
21 |
22 | - [hot100](https://gaowenxin95.github.io/leetcode-cookbook/leetcode-hot-100.html)
23 |
24 |
25 |
26 | 持续更新。。。
27 |
28 | 老铁们加油哇~
29 | 算法八股文必考~
30 | 基础不牢,地动山摇~
31 |
--------------------------------------------------------------------------------
/libs/gitbook-2.6.7/js/plugin-clipboard.js:
--------------------------------------------------------------------------------
1 | gitbook.require(["gitbook", "jQuery"], function(gitbook, $) {
2 |
3 | var copyButton = '';
4 | var clipboard;
5 |
6 | gitbook.events.bind("page.change", function() {
7 |
8 | if (!ClipboardJS.isSupported()) return;
9 |
10 | // the page.change event is thrown twice: before and after the page changes
11 | if (clipboard) {
12 | // clipboard is already defined
13 | // we can deduct that we are before page changes
14 | clipboard.destroy(); // destroy the previous events listeners
15 | clipboard = undefined; // reset the clipboard object
16 | return;
17 | }
18 |
19 | $(copyButton).prependTo("div.sourceCode");
20 |
21 | clipboard = new ClipboardJS(".copy-to-clipboard-button", {
22 | text: function(trigger) {
23 | return trigger.parentNode.textContent;
24 | }
25 | });
26 |
27 | });
28 |
29 | });
30 |
--------------------------------------------------------------------------------
/analysis/libs/gitbook-2.6.7/js/plugin-clipboard.js:
--------------------------------------------------------------------------------
1 | gitbook.require(["gitbook", "jQuery"], function(gitbook, $) {
2 |
3 | var copyButton = '';
4 | var clipboard;
5 |
6 | gitbook.events.bind("page.change", function() {
7 |
8 | if (!ClipboardJS.isSupported()) return;
9 |
10 | // the page.change event is thrown twice: before and after the page changes
11 | if (clipboard) {
12 | // clipboard is already defined
13 | // we can deduct that we are before page changes
14 | clipboard.destroy(); // destroy the previous events listeners
15 | clipboard = undefined; // reset the clipboard object
16 | return;
17 | }
18 |
19 | $(copyButton).prependTo("div.sourceCode");
20 |
21 | clipboard = new ClipboardJS(".copy-to-clipboard-button", {
22 | text: function(trigger) {
23 | return trigger.parentNode.textContent;
24 | }
25 | });
26 |
27 | });
28 |
29 | });
30 |
--------------------------------------------------------------------------------
/py_base.Rmd:
--------------------------------------------------------------------------------
1 | ---
2 | title: python基础
3 | author: 高文欣
4 | date: "`r Sys.Date()`"
5 | output:
6 | bookdown::gitbook:
7 | split_by: none
8 | split_bib: TRUE
9 | df_print: paged
10 | bibliography: refs/add.bib
11 | ---
12 |
13 | # python基础复习
14 |
15 | ## pop
16 |
17 | 这几个要记住,哈哈
18 |
19 | 还是切片那里的
20 |
21 | ```r
22 | sentence=['All', 'good', 'things', 'come', 'to' ,'those', 'who', 'wait.']
23 | print("默认为 index=-1,删除最后一个列表值:",sentence.pop(-1),"\n")
24 | print("默认删除最后一个列表值: ",sentence.pop(),"\n")
25 | print("删除第一个元素:",sentence.pop(0),"\n")
26 | print("删除第三个元素:",sentence.pop(2),"\n")print("输出剩余元素:",sentence)
27 |
28 | ```
29 |
30 | ### python切片复习
31 |
32 | object[start_index:end_index:step]
33 | step为正就是从左往右取值
34 | step为负就是从右往左取值
35 | 不包括end_index
36 | 参考[csdn](https://www.jianshu.com/p/15715d6f4dad)
37 |
38 | ```r
39 | a=['1','2','3']
40 | c=a[::-1]
41 | c
42 | #['3', '2', '1']
43 | ```
44 |
45 | 需要记住的几个
46 | ```r
47 | a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
48 |
49 | >>>a[:] #从左往右
50 | >>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
51 | >>>a[::]#从左往右
52 | >>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
53 | >>>a[::-1]#从右往左
54 | >>> [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
55 | ```
56 |
--------------------------------------------------------------------------------
/analysis/jiano.Rmd:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Untitled"
3 | author: "wenxin Gao"
4 | date: "2020/9/19"
5 | output: html_document
6 | ---
7 |
8 | ```{r,warning=FALSE}
9 |
10 |
11 | library(forecast)
12 | library(fUnitRoots)
13 |
14 | ```
15 |
16 | ```{r}
17 | data <- readxl::read_xlsx("D:/JupyterNotebook/E/data/n.xlsx")
18 |
19 | View(data)
20 |
21 | ```
22 |
23 | ```{r}
24 |
25 | library(devtools)
26 | #install_github('sinhrks/ggfortify')
27 | ```
28 |
29 | ```{r}
30 | library(ggplot2)
31 |
32 | ```
33 |
34 |
35 | ```{r}
36 | clears <- ts(data[,2])
37 | plot.ts(clears, xlab = "时间", ylab = "能见度")
38 | ```
39 |
40 |
41 | ```{r}
42 | library(magrittr)
43 | # 自相关图
44 | acf(data[,2])
45 |
46 | # 单位根检验
47 | unitrootTest(data[,2] %>% as.matrix())
48 |
49 | # 对原始序列进行 一阶差分,并进行 平稳性和白噪声检验
50 | # 一阶差分
51 | # 语法:(默认)diff(x, lag = 1, diff= 1, …)
52 | # 若x是一个数值向量,则表示后一项减前一项,即滞后一阶差分;
53 | # lag 表示滞后项
54 | # 如果要指定差分的阶数,则一定要使用带名称的参数:diff=2
55 |
56 | # sample表示样本数据。
57 | # 1、diff(sample,2)表示是对滞后2阶的数据进行差分,一阶差分,等同于:diff(sample,lag=2)
58 | # 2、diff(sample,diff=2)才是表示二阶差分
59 |
60 |
61 |
62 | # 单位根检验
63 | unitrootTest(data[,2]%>% as.matrix())
64 |
65 | # 白噪声检验
66 | Box.test(data[,2]%>% as.matrix(), type="Ljung-Box")
67 |
68 | # 偏自相关图
69 | pacf(data[,2])
70 |
71 | # ARIMA(1,1,0)模型
72 | # ARIMA(p,d,q)模型全称为差分自回归移动平均模型(Autoregressive Integrated Moving Average Model,简记ARIMA),
73 | # AR是自回归, p为自回归项;
74 | # MA为移动平均,q为移动平均项数;
75 | # d为时间序列成为平稳时所做的差分次数。
76 |
77 | arima <- arima(data[,2], order = c(1, 0, 1))
78 | arima
79 |
80 | # forecast <- forecast.Arima(arima, h = 5, level = c(99.5))
81 | forecast <- forecast(arima, h = 20, level = c(99.5))
82 | forecast
83 | plot(forecast)
84 |
85 | # tsdiag检验
86 | tsdiag(arima)
87 | ```
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/.Rproj.user/shared/notebooks/paths:
--------------------------------------------------------------------------------
1 | A:/Gaowenxin_notes/DL/deep_learn.Rmd="C7BDE1B7"
2 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/JZ_offer.Rmd="E14F3488"
3 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/Makefile="1E703314"
4 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/README.md="B0F96EDB"
5 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/analysis/DP.Rmd="B0AF1DB3"
6 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/analysis/array.Rmd="E52C0C24"
7 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/analysis/base_kg.Rmd="04FBF0E9"
8 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/analysis/huisu.Rmd="6E06B2EC"
9 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/analysis/jiano.Rmd="61CD4E8A"
10 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/analysis/k-num-sum.Rmd="FCF1A918"
11 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/analysis/lianbiao.Rmd="99467691"
12 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/analysis/sort.Rmd="1C57B973"
13 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/analysis/sort.py="E72360CE"
14 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/analysis/string.Rmd="C349C034"
15 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/analysis/summary.Rmd="8B6077AB"
16 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/analysis/tanxin.Rmd="8EAE5B20"
17 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/analysis/动态规划问题.html="56B60A73"
18 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/dandiao_stack.Rmd="6247395D"
19 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/erchashu.Rmd="3D5BB80E"
20 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/leetcode_hot.Rmd="D26671FD"
21 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/queue_and_stack.Rmd="7749EB00"
22 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/slide_window.Rmd="6B0866AD"
23 | A:/Gaowenxin_notes/leetcode/leetcode-cookbook/tree.Rmd="DE7086FA"
24 | A:/Lijiaxiang/learn_credit_risk/learning_notes.Rmd="306801AC"
25 | A:/Lijiaxiang/usd-dea/dev_history_r_proj.R="3BDE22BA"
26 |
--------------------------------------------------------------------------------
/analysis/sort.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/7/25 13:27
3 | # @Author : wenxin Gao
4 | # @Email : unique.gaowenxin@foxmail.com
5 | # @File : sort.py
6 | # @Software: PyCharm
7 |
8 | # 排序问题
9 |
10 |
11 |
12 |
13 | '''
14 | 冒泡排序算法
15 | 时间复杂度为$o^n$
16 | '''
17 |
18 | arr=[91,9,8,7,6,78,5,4,3,2,1]
19 |
20 | # def bub(arr):
21 | # for i in range(1,len(arr)):
22 | # for j in range(0,len(arr)-i):
23 | # if arr[j]>arr[j+1]:
24 | # arr[j+1],arr[j]=arr[j],arr[j+1]
25 | # return arr
26 | # l=bub(arr)
27 | # print(l)
28 |
29 |
30 |
31 |
32 | 目前来看两种写法是一样的
33 |
34 | '''
35 |
36 |
37 | '''
38 |
39 |
40 | '''
41 |
42 |
43 | '''
44 | 归并排序
45 |
46 | 采用分治之的方法进行排序,因此时间复杂度是nlog(n)
47 |
48 | 步骤
49 |
50 | 申请空间,使其大小为两个已经排序序列之和,该空间用来存放合并后的序列;
51 |
52 | 设定两个指针,最初位置分别为两个已经排序序列的起始位置;
53 |
54 | 比较两个指针所指向的元素,选择相对小的元素放入到合并空间,并移动指针到下一位置;
55 |
56 | 重复步骤 3 直到某一指针达到序列尾;
57 |
58 | 将另一序列剩下的所有元素直接复制到合并序列尾
59 |
60 | '''
61 |
62 | def mergeSort(arr):
63 | import math
64 | if(len(arr)<2):
65 | return arr
66 | middle = math.floor(len(arr)/2)
67 | left, right = arr[0:middle], arr[middle:]
68 | return merge(mergeSort(left), mergeSort(right))
69 |
70 | def merge(left,right):
71 | result = []
72 | while left and right:
73 | if left[0] <= right[0]:
74 | result.append(left.pop(0)); #还是要理解这个思想
75 | else:
76 | result.append(right.pop(0));
77 | while left:
78 | result.append(left.pop(0));
79 | while right:
80 | result.append(right.pop(0));
81 | return result
82 |
83 |
84 |
85 |
86 |
87 | '''
88 | 快速排序
89 |
90 | 在平均状况下,排序 n 个项目要 Ο(nlogn) 次比较。在最坏状况下则需要 Ο(n2) 次比较,但这种状况并不常见。事实上,快速排序通常明显比其他 Ο(nlogn) 算法更快,因为它的内部循环(inner loop)可以在大部分的架构上很有效率地被实现出来。
91 |
92 | 快速排序使用分治法(Divide and conquer)策略来把一个串行(list)分为两个子串行(sub-lists)。
93 | '''
94 |
95 |
96 | def quickSort(arr, left=None, right=None):
97 | left = 0 if not isinstance(left,(int, float)) else left
98 | right = len(arr)-1 if not isinstance(right,(int, float)) else right
99 | if left < right:
100 | partitionIndex = partition(arr, left, right)
101 | quickSort(arr, left, partitionIndex-1)
102 | quickSort(arr, partitionIndex+1, right)
103 | return arr
104 |
105 | def partition(arr, left, right):
106 | pivot = left
107 | index = pivot+1
108 | i = index
109 | while i <= right:
110 | if arr[i] < arr[pivot]:
111 | swap(arr, i, index)
112 | index+=1
113 | i+=1
114 | swap(arr,pivot,index-1)
115 | return index-1
116 |
117 | def swap(arr, i, j):
118 | arr[i], arr[j] = arr[j], arr[i]
119 |
120 |
121 |
122 | '''
123 |
--------------------------------------------------------------------------------
/libs/pagedtable-1.1/css/pagedtable.css:
--------------------------------------------------------------------------------
1 | .pagedtable {
2 | overflow: auto;
3 | padding-left: 8px;
4 | padding-right: 8px;
5 | }
6 |
7 | .pagedtable-wrapper {
8 | border: 1px solid #ccc;
9 | border-radius: 4px;
10 | margin-bottom: 10px;
11 | }
12 |
13 | .pagedtable table {
14 | width: 100%;
15 | max-width: 100%;
16 | margin: 0;
17 | }
18 |
19 | .pagedtable th {
20 | padding: 0 5px 0 5px;
21 | border: none;
22 | border-bottom: 2px solid #dddddd;
23 |
24 | min-width: 45px;
25 | }
26 |
27 | .pagedtable-empty th {
28 | display: none;
29 | }
30 |
31 | .pagedtable td {
32 | padding: 0 4px 0 4px;
33 | }
34 |
35 | .pagedtable .even {
36 | background-color: rgba(140, 140, 140, 0.1);
37 | }
38 |
39 | .pagedtable-padding-col {
40 | display: none;
41 | }
42 |
43 | .pagedtable a {
44 | -webkit-touch-callout: none;
45 | -webkit-user-select: none;
46 | -khtml-user-select: none;
47 | -moz-user-select: none;
48 | -ms-user-select: none;
49 | user-select: none;
50 | }
51 |
52 | .pagedtable-index-nav {
53 | cursor: pointer;
54 | padding: 0 5px 0 5px;
55 | float: right;
56 | border: 0;
57 | }
58 |
59 | .pagedtable-index-nav-disabled {
60 | cursor: default;
61 | text-decoration: none;
62 | color: #999;
63 | }
64 |
65 | a.pagedtable-index-nav-disabled:hover {
66 | text-decoration: none;
67 | color: #999;
68 | }
69 |
70 | .pagedtable-indexes {
71 | cursor: pointer;
72 | float: right;
73 | border: 0;
74 | }
75 |
76 | .pagedtable-index-current {
77 | cursor: default;
78 | text-decoration: none;
79 | font-weight: bold;
80 | color: #333;
81 | border: 0;
82 | }
83 |
84 | a.pagedtable-index-current:hover {
85 | text-decoration: none;
86 | font-weight: bold;
87 | color: #333;
88 | }
89 |
90 | .pagedtable-index {
91 | width: 30px;
92 | display: inline-block;
93 | text-align: center;
94 | border: 0;
95 | }
96 |
97 | .pagedtable-index-separator-left {
98 | display: inline-block;
99 | color: #333;
100 | font-size: 9px;
101 | padding: 0 0 0 0;
102 | cursor: default;
103 | }
104 |
105 | .pagedtable-index-separator-right {
106 | display: inline-block;
107 | color: #333;
108 | font-size: 9px;
109 | padding: 0 4px 0 0;
110 | cursor: default;
111 | }
112 |
113 | .pagedtable-footer {
114 | padding-top: 4px;
115 | padding-bottom: 5px;
116 | }
117 |
118 | .pagedtable-not-empty .pagedtable-footer {
119 | border-top: 2px solid #dddddd;
120 | }
121 |
122 | .pagedtable-info {
123 | overflow: hidden;
124 | color: #999;
125 | white-space: nowrap;
126 | text-overflow: ellipsis;
127 | }
128 |
129 | .pagedtable-header-name {
130 | overflow: hidden;
131 | text-overflow: ellipsis;
132 | }
133 |
134 | .pagedtable-header-type {
135 | color: #999;
136 | font-weight: 400;
137 | }
138 |
139 | .pagedtable-na-cell {
140 | font-style: italic;
141 | opacity: 0.3;
142 | }
143 |
--------------------------------------------------------------------------------
/libs/gitbook-2.6.7/css/plugin-bookdown.css:
--------------------------------------------------------------------------------
1 | .book .book-header h1 {
2 | padding-left: 20px;
3 | padding-right: 20px;
4 | }
5 | .book .book-header.fixed {
6 | position: fixed;
7 | right: 0;
8 | top: 0;
9 | left: 0;
10 | border-bottom: 1px solid rgba(0,0,0,.07);
11 | }
12 | span.search-highlight {
13 | background-color: #ffff88;
14 | }
15 | @media (min-width: 600px) {
16 | .book.with-summary .book-header.fixed {
17 | left: 300px;
18 | }
19 | }
20 | @media (max-width: 1240px) {
21 | .book .book-body.fixed {
22 | top: 50px;
23 | }
24 | .book .book-body.fixed .body-inner {
25 | top: auto;
26 | }
27 | }
28 | @media (max-width: 600px) {
29 | .book.with-summary .book-header.fixed {
30 | left: calc(100% - 60px);
31 | min-width: 300px;
32 | }
33 | .book.with-summary .book-body {
34 | transform: none;
35 | left: calc(100% - 60px);
36 | min-width: 300px;
37 | }
38 | .book .book-body.fixed {
39 | top: 0;
40 | }
41 | }
42 |
43 | .book .book-body.fixed .body-inner {
44 | top: 50px;
45 | }
46 | .book .book-body .page-wrapper .page-inner section.normal sub, .book .book-body .page-wrapper .page-inner section.normal sup {
47 | font-size: 85%;
48 | }
49 |
50 | @media print {
51 | .book .book-summary, .book .book-body .book-header, .fa {
52 | display: none !important;
53 | }
54 | .book .book-body.fixed {
55 | left: 0px;
56 | }
57 | .book .book-body,.book .book-body .body-inner, .book.with-summary {
58 | overflow: visible !important;
59 | }
60 | }
61 | .kable_wrapper {
62 | border-spacing: 20px 0;
63 | border-collapse: separate;
64 | border: none;
65 | margin: auto;
66 | }
67 | .kable_wrapper > tbody > tr > td {
68 | vertical-align: top;
69 | }
70 | .book .book-body .page-wrapper .page-inner section.normal table tr.header {
71 | border-top-width: 2px;
72 | }
73 | .book .book-body .page-wrapper .page-inner section.normal table tr:last-child td {
74 | border-bottom-width: 2px;
75 | }
76 | .book .book-body .page-wrapper .page-inner section.normal table td, .book .book-body .page-wrapper .page-inner section.normal table th {
77 | border-left: none;
78 | border-right: none;
79 | }
80 | .book .book-body .page-wrapper .page-inner section.normal table.kable_wrapper > tbody > tr, .book .book-body .page-wrapper .page-inner section.normal table.kable_wrapper > tbody > tr > td {
81 | border-top: none;
82 | }
83 | .book .book-body .page-wrapper .page-inner section.normal table.kable_wrapper > tbody > tr:last-child > td {
84 | border-bottom: none;
85 | }
86 |
87 | div.theorem, div.lemma, div.corollary, div.proposition, div.conjecture {
88 | font-style: italic;
89 | }
90 | span.theorem, span.lemma, span.corollary, span.proposition, span.conjecture {
91 | font-style: normal;
92 | }
93 | div.proof:after {
94 | content: "\25a2";
95 | float: right;
96 | }
97 | .header-section-number {
98 | padding-right: .5em;
99 | }
100 |
--------------------------------------------------------------------------------
/analysis/libs/gitbook-2.6.7/css/plugin-bookdown.css:
--------------------------------------------------------------------------------
1 | .book .book-header h1 {
2 | padding-left: 20px;
3 | padding-right: 20px;
4 | }
5 | .book .book-header.fixed {
6 | position: fixed;
7 | right: 0;
8 | top: 0;
9 | left: 0;
10 | border-bottom: 1px solid rgba(0,0,0,.07);
11 | }
12 | span.search-highlight {
13 | background-color: #ffff88;
14 | }
15 | @media (min-width: 600px) {
16 | .book.with-summary .book-header.fixed {
17 | left: 300px;
18 | }
19 | }
20 | @media (max-width: 1240px) {
21 | .book .book-body.fixed {
22 | top: 50px;
23 | }
24 | .book .book-body.fixed .body-inner {
25 | top: auto;
26 | }
27 | }
28 | @media (max-width: 600px) {
29 | .book.with-summary .book-header.fixed {
30 | left: calc(100% - 60px);
31 | min-width: 300px;
32 | }
33 | .book.with-summary .book-body {
34 | transform: none;
35 | left: calc(100% - 60px);
36 | min-width: 300px;
37 | }
38 | .book .book-body.fixed {
39 | top: 0;
40 | }
41 | }
42 |
43 | .book .book-body.fixed .body-inner {
44 | top: 50px;
45 | }
46 | .book .book-body .page-wrapper .page-inner section.normal sub, .book .book-body .page-wrapper .page-inner section.normal sup {
47 | font-size: 85%;
48 | }
49 |
50 | @media print {
51 | .book .book-summary, .book .book-body .book-header, .fa {
52 | display: none !important;
53 | }
54 | .book .book-body.fixed {
55 | left: 0px;
56 | }
57 | .book .book-body,.book .book-body .body-inner, .book.with-summary {
58 | overflow: visible !important;
59 | }
60 | }
61 | .kable_wrapper {
62 | border-spacing: 20px 0;
63 | border-collapse: separate;
64 | border: none;
65 | margin: auto;
66 | }
67 | .kable_wrapper > tbody > tr > td {
68 | vertical-align: top;
69 | }
70 | .book .book-body .page-wrapper .page-inner section.normal table tr.header {
71 | border-top-width: 2px;
72 | }
73 | .book .book-body .page-wrapper .page-inner section.normal table tr:last-child td {
74 | border-bottom-width: 2px;
75 | }
76 | .book .book-body .page-wrapper .page-inner section.normal table td, .book .book-body .page-wrapper .page-inner section.normal table th {
77 | border-left: none;
78 | border-right: none;
79 | }
80 | .book .book-body .page-wrapper .page-inner section.normal table.kable_wrapper > tbody > tr, .book .book-body .page-wrapper .page-inner section.normal table.kable_wrapper > tbody > tr > td {
81 | border-top: none;
82 | }
83 | .book .book-body .page-wrapper .page-inner section.normal table.kable_wrapper > tbody > tr:last-child > td {
84 | border-bottom: none;
85 | }
86 |
87 | div.theorem, div.lemma, div.corollary, div.proposition, div.conjecture {
88 | font-style: italic;
89 | }
90 | span.theorem, span.lemma, span.corollary, span.proposition, span.conjecture {
91 | font-style: normal;
92 | }
93 | div.proof:after {
94 | content: "\25a2";
95 | float: right;
96 | }
97 | .header-section-number {
98 | padding-right: .5em;
99 | }
100 |
--------------------------------------------------------------------------------
/libs/gitbook-2.6.7/js/jquery.highlight.js:
--------------------------------------------------------------------------------
1 | gitbook.require(["jQuery"], function(jQuery) {
2 |
3 | /*
4 | * jQuery Highlight plugin
5 | *
6 | * Based on highlight v3 by Johann Burkard
7 | * http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html
8 | *
9 | * Code a little bit refactored and cleaned (in my humble opinion).
10 | * Most important changes:
11 | * - has an option to highlight only entire words (wordsOnly - false by default),
12 | * - has an option to be case sensitive (caseSensitive - false by default)
13 | * - highlight element tag and class names can be specified in options
14 | *
15 | * Copyright (c) 2009 Bartek Szopka
16 | *
17 | * Licensed under MIT license.
18 | *
19 | */
20 |
21 | jQuery.extend({
22 | highlight: function (node, re, nodeName, className) {
23 | if (node.nodeType === 3) {
24 | var match = node.data.match(re);
25 | if (match) {
26 | var highlight = document.createElement(nodeName || 'span');
27 | highlight.className = className || 'highlight';
28 | var wordNode = node.splitText(match.index);
29 | wordNode.splitText(match[0].length);
30 | var wordClone = wordNode.cloneNode(true);
31 | highlight.appendChild(wordClone);
32 | wordNode.parentNode.replaceChild(highlight, wordNode);
33 | return 1; //skip added node in parent
34 | }
35 | } else if ((node.nodeType === 1 && node.childNodes) && // only element nodes that have children
36 | !/(script|style)/i.test(node.tagName) && // ignore script and style nodes
37 | !(node.tagName === nodeName.toUpperCase() && node.className === className)) { // skip if already highlighted
38 | for (var i = 0; i < node.childNodes.length; i++) {
39 | i += jQuery.highlight(node.childNodes[i], re, nodeName, className);
40 | }
41 | }
42 | return 0;
43 | }
44 | });
45 |
46 | jQuery.fn.unhighlight = function (options) {
47 | var settings = { className: 'highlight', element: 'span' };
48 | jQuery.extend(settings, options);
49 |
50 | return this.find(settings.element + "." + settings.className).each(function () {
51 | var parent = this.parentNode;
52 | parent.replaceChild(this.firstChild, this);
53 | parent.normalize();
54 | }).end();
55 | };
56 |
57 | jQuery.fn.highlight = function (words, options) {
58 | var settings = { className: 'highlight', element: 'span', caseSensitive: false, wordsOnly: false };
59 | jQuery.extend(settings, options);
60 |
61 | if (words.constructor === String) {
62 | words = [words];
63 | // also match 'foo-bar' if search for 'foo bar'
64 | if (/\s/.test(words[0])) words.push(words[0].replace(/\s+/, '-'));
65 | }
66 | words = jQuery.grep(words, function(word, i){
67 | return word !== '';
68 | });
69 | words = jQuery.map(words, function(word, i) {
70 | return word.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
71 | });
72 | if (words.length === 0) { return this; }
73 |
74 | var flag = settings.caseSensitive ? "" : "i";
75 | var pattern = "(" + words.join("|") + ")";
76 | if (settings.wordsOnly) {
77 | pattern = "\\b" + pattern + "\\b";
78 | }
79 | var re = new RegExp(pattern, flag);
80 |
81 | return this.each(function () {
82 | jQuery.highlight(this, re, settings.element, settings.className);
83 | });
84 | };
85 |
86 | });
87 |
--------------------------------------------------------------------------------
/analysis/libs/gitbook-2.6.7/js/jquery.highlight.js:
--------------------------------------------------------------------------------
1 | gitbook.require(["jQuery"], function(jQuery) {
2 |
3 | /*
4 | * jQuery Highlight plugin
5 | *
6 | * Based on highlight v3 by Johann Burkard
7 | * http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html
8 | *
9 | * Code a little bit refactored and cleaned (in my humble opinion).
10 | * Most important changes:
11 | * - has an option to highlight only entire words (wordsOnly - false by default),
12 | * - has an option to be case sensitive (caseSensitive - false by default)
13 | * - highlight element tag and class names can be specified in options
14 | *
15 | * Copyright (c) 2009 Bartek Szopka
16 | *
17 | * Licensed under MIT license.
18 | *
19 | */
20 |
21 | jQuery.extend({
22 | highlight: function (node, re, nodeName, className) {
23 | if (node.nodeType === 3) {
24 | var match = node.data.match(re);
25 | if (match) {
26 | var highlight = document.createElement(nodeName || 'span');
27 | highlight.className = className || 'highlight';
28 | var wordNode = node.splitText(match.index);
29 | wordNode.splitText(match[0].length);
30 | var wordClone = wordNode.cloneNode(true);
31 | highlight.appendChild(wordClone);
32 | wordNode.parentNode.replaceChild(highlight, wordNode);
33 | return 1; //skip added node in parent
34 | }
35 | } else if ((node.nodeType === 1 && node.childNodes) && // only element nodes that have children
36 | !/(script|style)/i.test(node.tagName) && // ignore script and style nodes
37 | !(node.tagName === nodeName.toUpperCase() && node.className === className)) { // skip if already highlighted
38 | for (var i = 0; i < node.childNodes.length; i++) {
39 | i += jQuery.highlight(node.childNodes[i], re, nodeName, className);
40 | }
41 | }
42 | return 0;
43 | }
44 | });
45 |
46 | jQuery.fn.unhighlight = function (options) {
47 | var settings = { className: 'highlight', element: 'span' };
48 | jQuery.extend(settings, options);
49 |
50 | return this.find(settings.element + "." + settings.className).each(function () {
51 | var parent = this.parentNode;
52 | parent.replaceChild(this.firstChild, this);
53 | parent.normalize();
54 | }).end();
55 | };
56 |
57 | jQuery.fn.highlight = function (words, options) {
58 | var settings = { className: 'highlight', element: 'span', caseSensitive: false, wordsOnly: false };
59 | jQuery.extend(settings, options);
60 |
61 | if (words.constructor === String) {
62 | words = [words];
63 | // also match 'foo-bar' if search for 'foo bar'
64 | if (/\s/.test(words[0])) words.push(words[0].replace(/\s+/, '-'));
65 | }
66 | words = jQuery.grep(words, function(word, i){
67 | return word !== '';
68 | });
69 | words = jQuery.map(words, function(word, i) {
70 | return word.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
71 | });
72 | if (words.length === 0) { return this; }
73 |
74 | var flag = settings.caseSensitive ? "" : "i";
75 | var pattern = "(" + words.join("|") + ")";
76 | if (settings.wordsOnly) {
77 | pattern = "\\b" + pattern + "\\b";
78 | }
79 | var re = new RegExp(pattern, flag);
80 |
81 | return this.each(function () {
82 | jQuery.highlight(this, re, settings.element, settings.className);
83 | });
84 | };
85 |
86 | });
87 |
--------------------------------------------------------------------------------
/analysis/base_kg.Rmd:
--------------------------------------------------------------------------------
1 | # 基础结构
2 |
3 | ## stack
4 |
5 | 后进先出,删除与加入均在**栈顶操作**
6 |
7 | 栈也称为堆栈,是一种**线性表**。
8 |
9 | 堆栈的特性: 最先放入堆栈中的内容最后被拿出来,最后放入堆栈中的内容最先被拿出来, 被称为先进后出、后进先出。
10 |
11 | 堆栈中两个最重要的操作是PUSH和POP,两个是相反的操作。
12 |
13 | PUSH:在堆栈的顶部加入一个元素。
14 |
15 | POP:在堆栈顶部移去一个元素, 并将堆栈的大小减一。
16 | 具体参考[「大羚羊」](https://blog.csdn.net/m0_37622530/article/details/81429837)
17 |
18 | 
19 |
20 | ## queue
21 |
22 |
23 | 队列——先进先出
24 |
25 | 队列也是一种特殊的线性表。不同于栈所服从的先进后出的原则,队列的原则是先进先出。
26 |
27 | 队列在队头做删除操作,在队尾做插入操作:
28 |
29 | 
30 |
31 | **我一直在想怎么可以把两种数据结构不记混,后来发现,画个图!**其次是“每日一遍,神清气爽~”
32 |
33 | 
34 |
35 | 主要考题:深度优先搜索和广度优先搜索(二叉树的层序遍历,先、中、后序遍历等)
36 |
37 | ### 数组实现栈
38 |
39 | ```r
40 |
41 | class Stack:
42 | def __init__(self, array = None):
43 | super().__init__()
44 | self.array = array
45 |
46 | # 入栈
47 | def push(self, x):
48 | self.array.append(x)
49 |
50 | # 出栈
51 | def pop(self,):
52 | if len(self.array) == 0:
53 | return
54 |
55 | return self.array.pop()
56 |
57 | # 取栈顶元素
58 | def top(self,):
59 | if len(self.array) == 0:
60 | return
61 |
62 | return self.array[-1]
63 |
64 | # 判空
65 | def isEmpty(self,):
66 | return True if self.array == [] else False
67 |
68 | ```
69 |
70 | ### 数组实现队列
71 |
72 | ```r
73 | class Queue:
74 | def __init__(self, array = None):
75 | super().__init__()
76 | self.array = array
77 |
78 | # 入队
79 | def enqueue(self, x):
80 | self.array.append(x)
81 |
82 | # 出队
83 | def dequeue(self):
84 | if len(self.array) == 0:
85 | return
86 |
87 | return self.array.pop(0)
88 |
89 | # 判空
90 | def isEmpty(self,):
91 | return True if self.array == [] else False
92 |
93 |
94 |
95 | ```
96 |
97 | ## 链表
98 |
99 | ### 单向链表
100 |
101 | >线性的顺序存储数据,而是在每一个节点里存到下一个节点的指针(Pointer)。由于不必须按顺序存储,链表的插入和删除操作可以达到O(1)的复杂度。
102 |
103 | 链表带指针~链表带指真~链表带指针~重要的事情说三遍!
104 |
105 |
106 | 循环链表是痛点!感觉链表题大部分也是画图,记得使用中间变量
107 |
108 | >链表是一种物理存储单元上非连续、非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的。链表由一系列结点(链表中每一个元素称为结点)组成,结点可以在运行时动态生成。每个结点包括两个部分:一个是存储数据元素的数据域,另一个是存储下一个结点地址的指针域。 相比于线性表顺序结构,操作复杂。由于不必须按顺序存储,链表在插入的时候可以达到O(1)的复杂度,比另一种线性表顺序表快得多,但是查找一个节点或者访问特定编号的节点则需要O(n)的时间,而线性表和顺序表相应的时间复杂度分别是O(logn)和O(1)。
109 | 使用链表结构可以克服数组链表需要预先知道数据大小的缺点,链表结构可以充分利用计算机内存空间,实现灵活的内存动态管理。但是链表失去了数组随机读取的优点,同时链表由于增加了结点的指针域,空间开销比较大。链表最明显的好处就是,常规数组排列关联项目的方式可能不同于这些数据项目在记忆体或磁盘上顺序,数据的存取往往要在不同的排列顺序中转换。链表允许插入和移除表上任意位置上的节点,但是不允许随机存取。链表有很多种不同的类型:单向链表,双向链表以及循环链表。链表可以在多种编程语言中实现。像Lisp和Scheme这样的语言的内建数据类型中就包含了链表的存取和操作[百度百科](https://baike.baidu.com/item/%E9%93%BE%E8%A1%A8/9794473?fr=aladdin)
110 |
111 | 做插入和删除操作的时候是链表更快,但是做查找的话,链表不如数组等顺序存储结构。
112 |
113 | 每个链表开头节点所带的指针叫head:头指针
114 |
115 | 
116 |
117 | 除了单项链表还有双向和循环链表
118 |
119 | ### 双向链表
120 |
121 | >双向链表也叫双链表,是链表的一种,它的每个数据结点中都有两个指针,分别指向直接后继和直接前驱。所以,从双向链表中的任意一个结点开始,都可以很方便地访问它的前驱结点和后继结点。一般我们都构造双向循环链表。[baike]https://baike.baidu.com/item/%E5%8F%8C%E5%90%91%E9%93%BE%E8%A1%A8/2968731?fr=aladdin)
122 |
123 | 
124 | ### 循环链表
125 |
126 | >表尾结点的next指针指向头结点
127 |
128 | 
129 |
130 |
131 | ## array
132 |
133 | 数组是用于储存多个相同类型数据的集合。
134 |
135 | ### 一维数组
136 |
137 |
138 |
139 | ### 二维数组
140 |
141 | ## tree
142 |
143 | ## 递归的思想
144 |
145 | 感觉大部分问题,应该是可以通过递归来解决的,但是理解起来总归是需要一段时间的.
146 |
147 | 遇到问题不用着急,先写出递推的逻辑,然后写出递归的终止条件
148 |
--------------------------------------------------------------------------------
/analysis/k-num-sum.Rmd:
--------------------------------------------------------------------------------
1 | ## 哈希表
2 |
3 | python中的字典的原理
4 |
5 |
6 |
7 | **前缀**
8 |
9 | 使用前缀数组的一大好处是可用 pre(b) - pre(a-1) 来表示 a->b 中这段中数组的和。这个 a-1 可以不用那么纠结。重点理解思想。
10 |
11 | 比如 前5项的和 - 前3项的和 = 第4项~第5项的和。 (1+2+3+4+5) - (1+2+3) = 4+5
12 |
13 | 这个前缀和数组 preSum 的含义也很好理解,preSum[i] 就是 nums[0..i-1] 的和。那么如果我们想求 nums[i..j] 的和,只需要一步操作 preSum[j+1]-preSum[i] 即可,而不需要重新去遍历数组了。
14 |
15 | ### K数之和
16 |
17 | 给定一个整数数组和一个整数 k,你需要找到该数组中和为 k 的连续的子数组的个数。
18 |
19 | 示例 1 :
20 |
21 | 输入:nums = [1,1,1], k = 2
22 | 输出: 2 , [1,1] 与 [1,1] 为两种不同的情况。
23 | 说明 :
24 |
25 | 数组的长度为 [1, 20,000]。
26 | 数组中元素的范围是 [-1000, 1000] ,且整数 k 的范围是 [-1e7, 1e7]。
27 |
28 |
29 |
30 | 这道题刚开始想到的思路是,先利用dp数组存放前i个数的和(前缀和),然后遍历这个数组,对于每个元素,求出dp[i]+k在dp[i:]的存在个数,即为以i+1开头的符合条件的子数组的个数,遍历结束把每个点的个数加在一起,即为答案。
31 |
32 | 分析可知,这种方法除了开始生成dp遍历了一次数组,在后面使用了双层循环,时间复杂度O(N^2),空间复杂度O(N)。
33 |
34 | 这种方法可以通过,但是耗时太多,那么,如果对时间复杂度进行优化呢。
35 |
36 | ==
37 |
38 | 使用哈希表(Python中字典原理)即可。抛弃dp数组,**只使用一个变量pre来保存当前位置的前缀和,使用一个字典dp,它的key是前缀和的值,对应的value表示这个前缀和出现的次数。**
39 |
40 | 在元素累加的过程中得到sum[j]=nums[0]+nums[1]+···+nums[j],并放入哈希表中。如果我们可以在哈希表中发现之前存在着sum[i]使得sum[j]-sum[i]=k,那么也就说明了有一个子序列之和为 k。时间复杂度终于被降到了$O(n)$。
41 |
42 | 首先添加dp[0] = 1,表示前缀和为0的情况出现了一次(这是为了考虑从i=0开始的答案),之后遍历数组,计算前缀和pre,加入dp(要判断pre是否存在,不存在写入,存在dp[pre]+=1),同时判断pre-k是否在dp字典中,如果在,ans+=dp[pre-k],说明存在dp[pre-k]种答案。最后返回ans即可。
43 |
44 | 。
45 | 这种情况只遍历了一次数组,字典中找值的过程时间复杂度O(1),所以总的时间复杂度O(N),只用到了一个变量和字典,空间复杂度O(N)。
46 |
47 | ```r
48 | class Solution:
49 | def subarraySum(self, nums: List[int], k: int) -> int:
50 | n = len(nums)
51 | pre = 0 #前缀和
52 | ans = 0
53 | dp = dict() #存放 前缀和:出现次数,键值对,初始化一个0:1,为了考虑到从头开始到某点的子数组正好为答案。
54 | dp[0] = 1
55 | for i in range(n):
56 | pre += nums[i] #计算前缀和
57 | if pre-k in dp: #如果pre-k这个前缀存在,那么答案加上它出现的次数
58 | ans += dp[pre-k]
59 | if pre in dp: #更新dp[pre]
60 | dp[pre] += 1
61 | else:
62 | dp[pre] = 1
63 | return ans
64 | ```
65 |
66 | ## 贪心算法
67 |
68 | ### 跳跃游戏
69 |
70 | 给定一个非负整数数组,你最初位于数组的第一个位置。
71 |
72 | 数组中的每个元素代表你在该位置可以跳跃的最大长度。
73 |
74 | 判断你是否能够到达最后一个位置。
75 |
76 | 示例 1:
77 |
78 | 输入: [2,3,1,1,4]
79 | 输出: true
80 | 解释: 我们可以先跳 1 步,从位置 0 到达 位置 1, 然后再从位置 1 跳 3 步到达最后一个位置。
81 |
82 | 示例 2:
83 |
84 | 输入: [3,2,1,0,4]
85 | 输出: false
86 | 解释: 无论怎样,你总会到达索引为 3 的位置。但该位置的最大跳跃长度是 0 , 所以你永远不可能到达最后一个位置。
87 |
88 | - 如果所有元素都不为0, 那么一定可以跳到最后;
89 | - 从后往前开始想,如果这个节点能够达到,那么下一个节点只要大于等于1就行,如果这个节点不能达到那么那么期待下一个节点要大于等于能达到的距离
90 |
91 | 可以用贪心的方法解决这个问题。
92 |
93 | 
94 |
95 | ```r
96 | class Solution:
97 | def canJump(self, nums) :
98 | max_i = 0 #初始化当前能到达最远的位置
99 | for i, jump in enumerate(nums): #i为当前位置,jump是当前位置的跳数
100 | if max_i>=i and i+jump>max_i: #如果当前位置能到达,并且当前位置+跳数>最远位置
101 | max_i = i+jump #更新最远能到达位置
102 | return max_i>=i
103 |
104 | ```
105 | ```r
106 | class Solution:
107 | def canJump(self, nums):
108 | """
109 | :type nums: List[int]
110 | :rtype: bool
111 | """
112 |
113 | maxPos = 0
114 | result = False
115 | for i in range(len(nums)-1):
116 | #如果历史最高高度达不到我们目前的index
117 | if maxPos < i:
118 | return False
119 | #更新历史最大值
120 | maxPos = max(maxPos, nums[i] + i)
121 |
122 | #判断是否完全通过
123 | if maxPos >= len(nums) - 1:
124 | result = True
125 |
126 | return result
127 | ```
128 |
129 | 时间复杂度:O(n),其中 n 为数组的大小。只需要访问 nums 数组一遍,共n 个位置。
130 |
131 | 空间复杂度:O(1),不需要额外的空间开销。
132 |
133 | >对于这种跳跃数组的问题,也就是要到达的位置与它的每一项关系紧密的问题,第一我们可以通过保存最大范围也就是历史最大index的方法去解决。第二,我们也可以尝试着用逆序去思考,看模拟每一步能不能走成功
134 |
--------------------------------------------------------------------------------
/libs/gitbook-2.6.7/js/plugin-sharing.js:
--------------------------------------------------------------------------------
1 | gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
2 | var SITES = {
3 | 'github': {
4 | 'label': 'Github',
5 | 'icon': 'fa fa-github',
6 | 'onClick': function(e) {
7 | e.preventDefault();
8 | var repo = $('meta[name="github-repo"]').attr('content');
9 | if (typeof repo === 'undefined') throw("Github repo not defined");
10 | window.open("https://github.com/"+repo);
11 | }
12 | },
13 | 'facebook': {
14 | 'label': 'Facebook',
15 | 'icon': 'fa fa-facebook',
16 | 'onClick': function(e) {
17 | e.preventDefault();
18 | window.open("http://www.facebook.com/sharer/sharer.php?u="+encodeURIComponent(location.href));
19 | }
20 | },
21 | 'twitter': {
22 | 'label': 'Twitter',
23 | 'icon': 'fa fa-twitter',
24 | 'onClick': function(e) {
25 | e.preventDefault();
26 | window.open("http://twitter.com/intent/tweet?text="+document.title+"&url="+encodeURIComponent(location.href)+"&hashtags=rmarkdown,bookdown");
27 | }
28 | },
29 | 'linkedin': {
30 | 'label': 'LinkedIn',
31 | 'icon': 'fa fa-linkedin',
32 | 'onClick': function(e) {
33 | e.preventDefault();
34 | window.open("https://www.linkedin.com/shareArticle?mini=true&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title));
35 | }
36 | },
37 | 'weibo': {
38 | 'label': 'Weibo',
39 | 'icon': 'fa fa-weibo',
40 | 'onClick': function(e) {
41 | e.preventDefault();
42 | window.open("http://service.weibo.com/share/share.php?content=utf-8&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title));
43 | }
44 | },
45 | 'instapaper': {
46 | 'label': 'Instapaper',
47 | 'icon': 'fa fa-italic',
48 | 'onClick': function(e) {
49 | e.preventDefault();
50 | window.open("http://www.instapaper.com/text?u="+encodeURIComponent(location.href));
51 | }
52 | },
53 | 'vk': {
54 | 'label': 'VK',
55 | 'icon': 'fa fa-vk',
56 | 'onClick': function(e) {
57 | e.preventDefault();
58 | window.open("http://vkontakte.ru/share.php?url="+encodeURIComponent(location.href));
59 | }
60 | }
61 | };
62 |
63 |
64 |
65 | gitbook.events.bind("start", function(e, config) {
66 | var opts = config.sharing;
67 | if (!opts) return;
68 |
69 | // Create dropdown menu
70 | var menu = _.chain(opts.all)
71 | .map(function(id) {
72 | var site = SITES[id];
73 | if (!site) return;
74 | return {
75 | text: site.label,
76 | onClick: site.onClick
77 | };
78 | })
79 | .compact()
80 | .value();
81 |
82 | // Create main button with dropdown
83 | if (menu.length > 0) {
84 | gitbook.toolbar.createButton({
85 | icon: 'fa fa-share-alt',
86 | label: 'Share',
87 | position: 'right',
88 | dropdown: [menu]
89 | });
90 | }
91 |
92 | // Direct actions to share
93 | _.each(SITES, function(site, sideId) {
94 | if (!opts[sideId]) return;
95 |
96 | gitbook.toolbar.createButton({
97 | icon: site.icon,
98 | label: site.label,
99 | title: site.label,
100 | position: 'right',
101 | onClick: site.onClick
102 | });
103 | });
104 | });
105 | });
106 |
--------------------------------------------------------------------------------
/analysis/libs/gitbook-2.6.7/js/plugin-sharing.js:
--------------------------------------------------------------------------------
1 | gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
2 | var SITES = {
3 | 'github': {
4 | 'label': 'Github',
5 | 'icon': 'fa fa-github',
6 | 'onClick': function(e) {
7 | e.preventDefault();
8 | var repo = $('meta[name="github-repo"]').attr('content');
9 | if (typeof repo === 'undefined') throw("Github repo not defined");
10 | window.open("https://github.com/"+repo);
11 | }
12 | },
13 | 'facebook': {
14 | 'label': 'Facebook',
15 | 'icon': 'fa fa-facebook',
16 | 'onClick': function(e) {
17 | e.preventDefault();
18 | window.open("http://www.facebook.com/sharer/sharer.php?u="+encodeURIComponent(location.href));
19 | }
20 | },
21 | 'twitter': {
22 | 'label': 'Twitter',
23 | 'icon': 'fa fa-twitter',
24 | 'onClick': function(e) {
25 | e.preventDefault();
26 | window.open("http://twitter.com/intent/tweet?text="+document.title+"&url="+encodeURIComponent(location.href)+"&hashtags=rmarkdown,bookdown");
27 | }
28 | },
29 | 'linkedin': {
30 | 'label': 'LinkedIn',
31 | 'icon': 'fa fa-linkedin',
32 | 'onClick': function(e) {
33 | e.preventDefault();
34 | window.open("https://www.linkedin.com/shareArticle?mini=true&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title));
35 | }
36 | },
37 | 'weibo': {
38 | 'label': 'Weibo',
39 | 'icon': 'fa fa-weibo',
40 | 'onClick': function(e) {
41 | e.preventDefault();
42 | window.open("http://service.weibo.com/share/share.php?content=utf-8&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title));
43 | }
44 | },
45 | 'instapaper': {
46 | 'label': 'Instapaper',
47 | 'icon': 'fa fa-italic',
48 | 'onClick': function(e) {
49 | e.preventDefault();
50 | window.open("http://www.instapaper.com/text?u="+encodeURIComponent(location.href));
51 | }
52 | },
53 | 'vk': {
54 | 'label': 'VK',
55 | 'icon': 'fa fa-vk',
56 | 'onClick': function(e) {
57 | e.preventDefault();
58 | window.open("http://vkontakte.ru/share.php?url="+encodeURIComponent(location.href));
59 | }
60 | }
61 | };
62 |
63 |
64 |
65 | gitbook.events.bind("start", function(e, config) {
66 | var opts = config.sharing;
67 | if (!opts) return;
68 |
69 | // Create dropdown menu
70 | var menu = _.chain(opts.all)
71 | .map(function(id) {
72 | var site = SITES[id];
73 | if (!site) return;
74 | return {
75 | text: site.label,
76 | onClick: site.onClick
77 | };
78 | })
79 | .compact()
80 | .value();
81 |
82 | // Create main button with dropdown
83 | if (menu.length > 0) {
84 | gitbook.toolbar.createButton({
85 | icon: 'fa fa-share-alt',
86 | label: 'Share',
87 | position: 'right',
88 | dropdown: [menu]
89 | });
90 | }
91 |
92 | // Direct actions to share
93 | _.each(SITES, function(site, sideId) {
94 | if (!opts[sideId]) return;
95 |
96 | gitbook.toolbar.createButton({
97 | icon: site.icon,
98 | label: site.label,
99 | title: site.label,
100 | position: 'right',
101 | onClick: site.onClick
102 | });
103 | });
104 | });
105 | });
106 |
--------------------------------------------------------------------------------
/libs/gitbook-2.6.7/js/plugin-fontsettings.js:
--------------------------------------------------------------------------------
1 | gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
2 | var fontState;
3 |
4 | var THEMES = {
5 | "white": 0,
6 | "sepia": 1,
7 | "night": 2
8 | };
9 |
10 | var FAMILY = {
11 | "serif": 0,
12 | "sans": 1
13 | };
14 |
15 | // Save current font settings
16 | function saveFontSettings() {
17 | gitbook.storage.set("fontState", fontState);
18 | update();
19 | }
20 |
21 | // Increase font size
22 | function enlargeFontSize(e) {
23 | e.preventDefault();
24 | if (fontState.size >= 4) return;
25 |
26 | fontState.size++;
27 | saveFontSettings();
28 | };
29 |
30 | // Decrease font size
31 | function reduceFontSize(e) {
32 | e.preventDefault();
33 | if (fontState.size <= 0) return;
34 |
35 | fontState.size--;
36 | saveFontSettings();
37 | };
38 |
39 | // Change font family
40 | function changeFontFamily(index, e) {
41 | e.preventDefault();
42 |
43 | fontState.family = index;
44 | saveFontSettings();
45 | };
46 |
47 | // Change type of color
48 | function changeColorTheme(index, e) {
49 | e.preventDefault();
50 |
51 | var $book = $(".book");
52 |
53 | if (fontState.theme !== 0)
54 | $book.removeClass("color-theme-"+fontState.theme);
55 |
56 | fontState.theme = index;
57 | if (fontState.theme !== 0)
58 | $book.addClass("color-theme-"+fontState.theme);
59 |
60 | saveFontSettings();
61 | };
62 |
63 | function update() {
64 | var $book = gitbook.state.$book;
65 |
66 | $(".font-settings .font-family-list li").removeClass("active");
67 | $(".font-settings .font-family-list li:nth-child("+(fontState.family+1)+")").addClass("active");
68 |
69 | $book[0].className = $book[0].className.replace(/\bfont-\S+/g, '');
70 | $book.addClass("font-size-"+fontState.size);
71 | $book.addClass("font-family-"+fontState.family);
72 |
73 | if(fontState.theme !== 0) {
74 | $book[0].className = $book[0].className.replace(/\bcolor-theme-\S+/g, '');
75 | $book.addClass("color-theme-"+fontState.theme);
76 | }
77 | };
78 |
79 | function init(config) {
80 | var $bookBody, $book;
81 |
82 | //Find DOM elements.
83 | $book = gitbook.state.$book;
84 | $bookBody = $book.find(".book-body");
85 |
86 | // Instantiate font state object
87 | fontState = gitbook.storage.get("fontState", {
88 | size: config.size || 2,
89 | family: FAMILY[config.family || "sans"],
90 | theme: THEMES[config.theme || "white"]
91 | });
92 |
93 | update();
94 | };
95 |
96 |
97 | gitbook.events.bind("start", function(e, config) {
98 | var opts = config.fontsettings;
99 | if (!opts) return;
100 |
101 | // Create buttons in toolbar
102 | gitbook.toolbar.createButton({
103 | icon: 'fa fa-font',
104 | label: 'Font Settings',
105 | className: 'font-settings',
106 | dropdown: [
107 | [
108 | {
109 | text: 'A',
110 | className: 'font-reduce',
111 | onClick: reduceFontSize
112 | },
113 | {
114 | text: 'A',
115 | className: 'font-enlarge',
116 | onClick: enlargeFontSize
117 | }
118 | ],
119 | [
120 | {
121 | text: 'Serif',
122 | onClick: _.partial(changeFontFamily, 0)
123 | },
124 | {
125 | text: 'Sans',
126 | onClick: _.partial(changeFontFamily, 1)
127 | }
128 | ],
129 | [
130 | {
131 | text: 'White',
132 | onClick: _.partial(changeColorTheme, 0)
133 | },
134 | {
135 | text: 'Sepia',
136 | onClick: _.partial(changeColorTheme, 1)
137 | },
138 | {
139 | text: 'Night',
140 | onClick: _.partial(changeColorTheme, 2)
141 | }
142 | ]
143 | ]
144 | });
145 |
146 |
147 | // Init current settings
148 | init(opts);
149 | });
150 | });
151 |
152 |
153 |
--------------------------------------------------------------------------------
/analysis/libs/gitbook-2.6.7/js/plugin-fontsettings.js:
--------------------------------------------------------------------------------
1 | gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
2 | var fontState;
3 |
4 | var THEMES = {
5 | "white": 0,
6 | "sepia": 1,
7 | "night": 2
8 | };
9 |
10 | var FAMILY = {
11 | "serif": 0,
12 | "sans": 1
13 | };
14 |
15 | // Save current font settings
16 | function saveFontSettings() {
17 | gitbook.storage.set("fontState", fontState);
18 | update();
19 | }
20 |
21 | // Increase font size
22 | function enlargeFontSize(e) {
23 | e.preventDefault();
24 | if (fontState.size >= 4) return;
25 |
26 | fontState.size++;
27 | saveFontSettings();
28 | };
29 |
30 | // Decrease font size
31 | function reduceFontSize(e) {
32 | e.preventDefault();
33 | if (fontState.size <= 0) return;
34 |
35 | fontState.size--;
36 | saveFontSettings();
37 | };
38 |
39 | // Change font family
40 | function changeFontFamily(index, e) {
41 | e.preventDefault();
42 |
43 | fontState.family = index;
44 | saveFontSettings();
45 | };
46 |
47 | // Change type of color
48 | function changeColorTheme(index, e) {
49 | e.preventDefault();
50 |
51 | var $book = $(".book");
52 |
53 | if (fontState.theme !== 0)
54 | $book.removeClass("color-theme-"+fontState.theme);
55 |
56 | fontState.theme = index;
57 | if (fontState.theme !== 0)
58 | $book.addClass("color-theme-"+fontState.theme);
59 |
60 | saveFontSettings();
61 | };
62 |
63 | function update() {
64 | var $book = gitbook.state.$book;
65 |
66 | $(".font-settings .font-family-list li").removeClass("active");
67 | $(".font-settings .font-family-list li:nth-child("+(fontState.family+1)+")").addClass("active");
68 |
69 | $book[0].className = $book[0].className.replace(/\bfont-\S+/g, '');
70 | $book.addClass("font-size-"+fontState.size);
71 | $book.addClass("font-family-"+fontState.family);
72 |
73 | if(fontState.theme !== 0) {
74 | $book[0].className = $book[0].className.replace(/\bcolor-theme-\S+/g, '');
75 | $book.addClass("color-theme-"+fontState.theme);
76 | }
77 | };
78 |
79 | function init(config) {
80 | var $bookBody, $book;
81 |
82 | //Find DOM elements.
83 | $book = gitbook.state.$book;
84 | $bookBody = $book.find(".book-body");
85 |
86 | // Instantiate font state object
87 | fontState = gitbook.storage.get("fontState", {
88 | size: config.size || 2,
89 | family: FAMILY[config.family || "sans"],
90 | theme: THEMES[config.theme || "white"]
91 | });
92 |
93 | update();
94 | };
95 |
96 |
97 | gitbook.events.bind("start", function(e, config) {
98 | var opts = config.fontsettings;
99 | if (!opts) return;
100 |
101 | // Create buttons in toolbar
102 | gitbook.toolbar.createButton({
103 | icon: 'fa fa-font',
104 | label: 'Font Settings',
105 | className: 'font-settings',
106 | dropdown: [
107 | [
108 | {
109 | text: 'A',
110 | className: 'font-reduce',
111 | onClick: reduceFontSize
112 | },
113 | {
114 | text: 'A',
115 | className: 'font-enlarge',
116 | onClick: enlargeFontSize
117 | }
118 | ],
119 | [
120 | {
121 | text: 'Serif',
122 | onClick: _.partial(changeFontFamily, 0)
123 | },
124 | {
125 | text: 'Sans',
126 | onClick: _.partial(changeFontFamily, 1)
127 | }
128 | ],
129 | [
130 | {
131 | text: 'White',
132 | onClick: _.partial(changeColorTheme, 0)
133 | },
134 | {
135 | text: 'Sepia',
136 | onClick: _.partial(changeColorTheme, 1)
137 | },
138 | {
139 | text: 'Night',
140 | onClick: _.partial(changeColorTheme, 2)
141 | }
142 | ]
143 | ]
144 | });
145 |
146 |
147 | // Init current settings
148 | init(opts);
149 | });
150 | });
151 |
152 |
153 |
--------------------------------------------------------------------------------
/.Rproj.user/4A13D082/sources/prop/INDEX:
--------------------------------------------------------------------------------
1 | A%3A%2FGaowenxin_notes%2FDL%2Fdeep_learn.Rmd="7D30E6E5"
2 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2FJZ_offer.Rmd="B6121ABB"
3 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2FMakefile="F6B97466"
4 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2FR%2Fcalc_woe.R="A4CD0DFC"
5 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2FREADME.md="9231311B"
6 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fanalysis%2FDP.Rmd="0AEDBE83"
7 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fanalysis%2Farray.Rmd="640A0840"
8 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fanalysis%2Fbase_kg.Rmd="C425B331"
9 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fanalysis%2Fhuisu.Rmd="EC98685D"
10 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fanalysis%2Fjiano.Rmd="273FFFF4"
11 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fanalysis%2Fk-num-sum.Rmd="7836F524"
12 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fanalysis%2Fleetcode.Rmd="F0CB30BC"
13 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fanalysis%2Flianbiao.Rmd="75B7BA78"
14 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fanalysis%2Fsort.Rmd="6EF22B8E"
15 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fanalysis%2Fsort.py="C8EC9777"
16 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fanalysis%2Fstring.Rmd="218D07AE"
17 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fanalysis%2Fstring.html="9603485A"
18 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fanalysis%2Fsummary.Rmd="B388D734"
19 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fanalysis%2Ftanxin.Rmd="D81B219D"
20 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fanalysis%2Ftime_complexity.Rmd="7516B97D"
21 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fcode%2Fbuild-jupyter-notebook.R="1B28BD80"
22 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fcode%2Fbuild-model-notes.R="CE2753F1"
23 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fcode%2Fbuild-readme.R="32335F09"
24 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fcode%2Fbuild.R="2E529242"
25 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fcode%2Fclean.R="D0A7FD8C"
26 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fcode%2Fcopy-md.R="9002298D"
27 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fcode%2Fpush.R="1BF2BFA0"
28 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fcxmsbd.Rmd="9200D031"
29 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fcxmsbd_py.Rmd="CB210309"
30 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fec.Rmd="91164974"
31 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Ferchashu.Rmd="1CE5C906"
32 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fleetcode.Rmd="6B4EB6C4"
33 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Fpy_base.Rmd="004A92D8"
34 | A%3A%2FGaowenxin_notes%2Fle_leetcode%2Ftree.Rmd="C354AE86"
35 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2FJZ_offer.Rmd="DFE47971"
36 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2FMakefile="F09DAD79"
37 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2FREADME.md="F49B45D8"
38 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Fanalysis%2F%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92%E9%97%AE%E9%A2%98.html="057DD778"
39 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Fanalysis%2FDP.Rmd="CDCF8015"
40 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Fanalysis%2Farray.Rmd="30E39A56"
41 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Fanalysis%2Fbase_kg.Rmd="4CF42BE3"
42 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Fanalysis%2Fdandiao_stack.Rmd="278D01CC"
43 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Fanalysis%2Fhuisu.Rmd="3B83C718"
44 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Fanalysis%2Fjiano.Rmd="13519BB2"
45 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Fanalysis%2Fk-num-sum.Rmd="E154C21D"
46 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Fanalysis%2Flianbiao.Rmd="A3266D02"
47 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Fanalysis%2Fsort.Rmd="52D9BB00"
48 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Fanalysis%2Fsort.py="BB4CEBA7"
49 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Fanalysis%2Fstring.Rmd="8483E3E1"
50 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Fanalysis%2Fsummary.Rmd="79425DAB"
51 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Fanalysis%2Ftanxin.Rmd="7102EA36"
52 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Fdandiao_stack.Rmd="6A154252"
53 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Ferchashu.Rmd="3D9C9DC3"
54 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Fleetcode_hot.Rmd="B115194C"
55 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Fqueue_and_stack.Rmd="3536E7CE"
56 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Fslide_window.Rmd="AFC7CA29"
57 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Ftree.Rmd="0EBEF394"
58 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Ftree.html="5103E99D"
59 | A%3A%2FGaowenxin_notes%2Fleetcode%2Fleetcode-cookbook%2Ftwo_tree.Rmd="145E0D85"
60 | A%3A%2FGaowenxin_notes%2Fleetcode-cookbook%2Fleetcode-cookbook.Rmd="A6145623"
61 | A%3A%2FGaowenxin_notes%2Fleetcode-cookbook%2Fleetcode.Rmd="800F1B8A"
62 | A%3A%2FLijiaxiang%2Flearn_credit_risk%2Flearning_notes.Rmd="3343B2B3"
63 | A%3A%2FLijiaxiang%2Fusd-dea%2Fdev_history_r_proj.R="2A3D5609"
64 |
--------------------------------------------------------------------------------
/栈和队列.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | 栈和队列
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
76 |
77 |
78 |
79 |
80 |
85 |
86 |
87 |
88 |
89 |
90 |
95 |
96 |
栈和队列
97 |
98 |
栈与递归的关系
99 |
通常,当在一个函数的运行期间调用另一个函数时,在运行被调用函数之前,系统要做三件事:
100 |
101 | - 将所有的实参,返回地址等信息调用传递给被调用函数保存;
102 | - 为被调用函数的局部变量分配存储空间;
103 | - 将控制权转移到被调用函数入口;
104 |
105 |
一个递归函数的运行过程类似多个函数的嵌套调用,只是调用函数和被调用函数都是同一个函数,因此,每次调用本身时,就会产生一个调用相关的一个重要概念就是递归函数运行的“层次”.假设调用该递归函数的主函数为第0层,则从主函数调用递归函数进入到第一层,从第i层递归调用本函数进入下一层为第i+1层,反之退出第i层递归函数返回上一层为第i-1层;
106 | 为了保证递归函数正确执行,系统需要设立一个“递归工作栈”作为整个递归函数运行期间使用的数据存储区,每一层递归所需信息构成一个工作记录,其中包括所有实参,所有局部变量以及上一层的返回地址.每进入一层递归,就产生一个新的工作记录压入栈顶,每退出一个递归,就从栈顶弹出一个工作记录,则当前执行层的工作记录必须是递归工作栈栈顶的工作记录,此称为“活动记录”;【ChaosHeart】
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
165 |
166 |
167 |
168 |
169 |
--------------------------------------------------------------------------------
/analysis/array.Rmd:
--------------------------------------------------------------------------------
1 | ---
2 | title : 数组专题
3 | author: 高文欣
4 | date: "`r Sys.Date()`"
5 | output: bookdown::gitbook
6 | bibliography: ../refs/add.bib
7 | ---
8 |
9 | # 数组专题
10 |
11 | ## 长度最小的子数组
12 |
13 | - 题目描述
14 |
15 | 给定一个含有 n 个正整数的数组和一个正整数 target 。
16 |
17 | 找出该数组中满足其和 ≥ target 的长度最小的 连续子数组 [numsl, numsl+1, ..., numsr-1, numsr] ,并返回其长度。如果不存在符合条件的子数组,返回 0 。
18 |
19 |
20 | - 解题思路
21 |
22 | 比较典型的滑动窗口
23 |
24 | 主要确定如下三点:
25 |
26 | - 窗口内是什么?
27 | - 如何移动窗口的起始位置?
28 | - 如何移动窗口的结束位置?
29 |
30 | >窗口就是 满足其和 ≥ s 的长度最小的连续子数组。
31 | 窗口的起始位置如何移动:如果当前窗口的值大于s了,窗口就要向前移动了(也就是该缩小了)。
32 | 窗口的结束位置如何移动:窗口的结束位置就是遍历数组的指针,窗口的起始位置设置为数组的起始位置就可以了。
33 | 解题的关键在于 窗口的起始位置如何移动,如图所示:
34 |
35 | 
36 |
37 |
38 | ```r
39 | class Solution:
40 | def minSubArrayLen(self, s: int, nums: List[int]) -> int:
41 | # 定义一个无限大的数
42 | res = float("inf")
43 | Sum = 0 # 当前总和
44 | index = 0 # 当前索引
45 | for i in range(len(nums)):
46 | Sum += nums[i]
47 | while Sum >= s:
48 | res = min(res, i-index+1)
49 | Sum -= nums[index] # 滑动窗口的精髓,不断变更index
50 | index += 1
51 | return 0 if res==float("inf") else res
52 | ```
53 |
54 |
55 |
56 | ## 两个数组的交集
57 |
58 | - 题目描述
59 |
60 | 给定两个数组,编写一个函数来计算它们的交集。
61 | 输入: nums1 = [1,2,2,1], nums2 = [2,2]
62 | 输出: [2,2]
63 |
64 |
65 | ```r
66 | res=[]
67 | def jiaoji(nums1,nums2):
68 | for k in nums2:
69 | if k in nums1:
70 | res.append(k)
71 | nums1.remove(k)
72 | return res
73 |
74 | print(jiaoji(nums1,nums2))
75 | ```
76 |
77 |
78 |
79 | ## 旋转数组
80 |
81 | - 题目描述
82 |
83 | 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。
84 | 示例 1:
85 | 输入: [1,2,3,4,5,6,7] 和 k = 3
86 | 输出: [5,6,7,1,2,3,4]
87 |
88 | ```r
89 | arr=[1,2,3,4,5,6,7]
90 | def xz(nums,k):
91 | return nums[k:]+nums[:k]
92 |
93 | print(xz(arr,3))
94 | ```
95 |
96 | ## 移除元素
97 |
98 | - 题目描述
99 | >
100 | #给你一个数组 nums 和一个值 val,你需要 原地 移除所有数值等于 val 的元素,并返回移除后数组的新长度。
101 |
102 | 不要使用额外的数组空间,你必须仅使用 O(1) 额外空间并原地修改输入数组。
103 |
104 | 元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素。
105 |
106 | 示例 1: 给定 nums = [3,2,2,3], val = 3, 函数应该返回新的长度 2, 并且 nums 中的前两个元素均为 2。 你不需要考虑数组中超出新长度后面的元素。
107 |
108 | 示例 2: 给定 nums = [0,1,2,2,3,0,4,2], val = 2, 函数应该返回新的长度 5, 并且 nums 中的前五个元素为 0, 1, 3, 0, 4。
109 |
110 | 你不需要考虑数组中超出新长度后面的元素。
111 |
112 | - 解题思路
113 |
114 | 还是指针
115 |
116 | ``` r
117 |
118 | class Solution:
119 | def removeElement(self, nums: List[int], val: int) -> int:
120 | i,n = 0,len(nums)
121 | for j in range(n):
122 | if nums[j] != val:
123 | nums[i] = nums[j]
124 | i += 1
125 | return i
126 | ```
127 |
128 | ## 加一
129 |
130 | - 题目描述
131 |
132 | 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一。
133 |
134 | 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字。
135 |
136 | 你可以假设除了整数 0 之外,这个整数不会以零开头。
137 |
138 | 示例 1:
139 |
140 | 输入: [1,2,3]
141 | 输出: [1,2,4]
142 | 解释: 输入数组表示数字 123。
143 | 示例 2:
144 |
145 | 输入: [4,3,2,1]
146 | 输出: [4,3,2,2]
147 | 解释: 输入数组表示数字 4321。
148 |
149 | 解题思路是转化为数字加完了再转化为数组
150 |
151 | ``` r
152 | s=[4,3,2,1]
153 | def jiayi(s):
154 | nus=[v*10**index for index,v in enumerate(s[::-1])]
155 | newv=sum(nus)+1
156 | return [int(x) for x in str(newv)]
157 |
158 |
159 | print(jiayi(s))
160 | ```
161 |
162 | ## 两数之和
163 |
164 | 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。
165 | 你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。
166 |
167 | 示例:
168 |
169 | 给定 nums = [2, 7, 11, 15], target = 9
170 | 因为 nums[0] + nums[1] = 2 + 7 = 9
171 | 所以返回 [0, 1]
172 |
173 | ```r
174 |
175 | def twoSum(nums, target) :
176 | d = {}
177 | for k, v in enumerate(nums):
178 | if target - v in d:
179 | return [d[target - v], k]
180 | d[v] = k
181 | print(twoSum(nums,target))
182 |
183 | ```
184 |
185 | ## 三数之和
186 |
187 | 给你一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c
188 | ,使得 a + b + c = 0 ?请你找出所有满足条件且不重复的三元组。
189 |
190 | 注意:答案中不可以包含重复的三元组。
191 |
192 |
193 |
194 | 示例:
195 |
196 | 给定数组 nums = [-1, 0, 1, 2, -1, -4],
197 |
198 | 满足要求的三元组集合为: [ [-1, 0, 1], [-1, -1, 2]]
199 |
200 | - 解题思路
201 |
202 | 这个题,哎只能想到贼暴力的解法,看了大佬们的解法,只能惊叹!!牛逼的太多了
203 |
204 | 排序 + 双指针 本题的难点在于如何去除重复解。 算法流程:
205 | 1.特判,对于数组长度 $n,$ 如果数组为 $n u l l$ 或者数组长度小于 $3,$ 返回
206 | []$.$
207 | 2. 对数组进行排序。
208 | 3. 遍历排序后数组。若 $n u m s[i]>0:$
209 | 因为已经排序好, 所以后面不可能有三个数加和等于 0,直接返回结果。
210 | 对于重复元素:跳过, 避免出现重复解 令左指针 $L=i+1,$ 右指针 $R=n-1,$ 当
211 | $L List[List[int]]:
223 |
224 | n=len(nums)
225 | res=[]
226 | if(not nums or n<3):
227 | return []
228 | nums.sort() # 先排序
229 | res=[] # 定义一个结果list
230 | for i in range(n): # 如果元素都大于0,无解
231 | if(nums[i]>0):
232 | return res
233 | if(i>0 and nums[i]==nums[i-1]):
234 | continue
235 | L=i+1 # 明显的滑动窗口
236 | R=n-1
237 | while(L0):
247 | R=R-1
248 | else:
249 | L=L+1
250 | return res
251 |
252 | ```
253 |
254 | ## 合并两个有序数组
255 |
256 |
257 | ```r
258 | def merge(A,m,B,n):
259 | A[m:m+n] = B # 直接扩展数组A
260 | A.sort()
261 |
262 | if __name__ == "__main__":
263 | A = [4,5,6]
264 | B = [1,2,3]
265 | merge(A,3,B,3)
266 | print(A)
267 |
268 | ```
269 |
270 |
271 |
272 |
273 |
274 |
--------------------------------------------------------------------------------
/libs/gitbook-2.6.7/js/plugin-search.js:
--------------------------------------------------------------------------------
1 | gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
2 | var index = null;
3 | var $searchInput, $searchLabel, $searchForm;
4 | var $highlighted = [], hi, hiOpts = { className: 'search-highlight' };
5 | var collapse = false, toc_visible = [];
6 |
7 | // Use a specific index
8 | function loadIndex(data) {
9 | // [Yihui] In bookdown, I use a character matrix to store the chapter
10 | // content, and the index is dynamically built on the client side.
11 | // Gitbook prebuilds the index data instead: https://github.com/GitbookIO/plugin-search
12 | // We can certainly do that via R packages V8 and jsonlite, but let's
13 | // see how slow it really is before improving it. On the other hand,
14 | // lunr cannot handle non-English text very well, e.g. the default
15 | // tokenizer cannot deal with Chinese text, so we may want to replace
16 | // lunr with a dumb simple text matching approach.
17 | index = lunr(function () {
18 | this.ref('url');
19 | this.field('title', { boost: 10 });
20 | this.field('body');
21 | });
22 | data.map(function(item) {
23 | index.add({
24 | url: item[0],
25 | title: item[1],
26 | body: item[2]
27 | });
28 | });
29 | }
30 |
31 | // Fetch the search index
32 | function fetchIndex() {
33 | return $.getJSON(gitbook.state.basePath+"/search_index.json")
34 | .then(loadIndex); // [Yihui] we need to use this object later
35 | }
36 |
37 | // Search for a term and return results
38 | function search(q) {
39 | if (!index) return;
40 |
41 | var results = _.chain(index.search(q))
42 | .map(function(result) {
43 | var parts = result.ref.split("#");
44 | return {
45 | path: parts[0],
46 | hash: parts[1]
47 | };
48 | })
49 | .value();
50 |
51 | // [Yihui] Highlight the search keyword on current page
52 | $highlighted = results.length === 0 ? [] : $('.page-inner')
53 | .unhighlight(hiOpts).highlight(q, hiOpts).find('span.search-highlight');
54 | scrollToHighlighted(0);
55 |
56 | return results;
57 | }
58 |
59 | // [Yihui] Scroll the chapter body to the i-th highlighted string
60 | function scrollToHighlighted(d) {
61 | var n = $highlighted.length;
62 | hi = hi === undefined ? 0 : hi + d;
63 | // navignate to the previous/next page in the search results if reached the top/bottom
64 | var b = hi < 0;
65 | if (d !== 0 && (b || hi >= n)) {
66 | var path = currentPath(), n2 = toc_visible.length;
67 | if (n2 === 0) return;
68 | for (var i = b ? 0 : n2; (b && i < n2) || (!b && i >= 0); i += b ? 1 : -1) {
69 | if (toc_visible.eq(i).data('path') === path) break;
70 | }
71 | i += b ? -1 : 1;
72 | if (i < 0) i = n2 - 1;
73 | if (i >= n2) i = 0;
74 | var lnk = toc_visible.eq(i).find('a[href$=".html"]');
75 | if (lnk.length) lnk[0].click();
76 | return;
77 | }
78 | if (n === 0) return;
79 | var $p = $highlighted.eq(hi);
80 | $p[0].scrollIntoView();
81 | $highlighted.css('background-color', '');
82 | // an orange background color on the current item and removed later
83 | $p.css('background-color', 'orange');
84 | setTimeout(function() {
85 | $p.css('background-color', '');
86 | }, 2000);
87 | }
88 |
89 | function currentPath() {
90 | var href = window.location.pathname;
91 | href = href.substr(href.lastIndexOf('/') + 1);
92 | return href === '' ? 'index.html' : href;
93 | }
94 |
95 | // Create search form
96 | function createForm(value) {
97 | if ($searchForm) $searchForm.remove();
98 | if ($searchLabel) $searchLabel.remove();
99 | if ($searchInput) $searchInput.remove();
100 |
101 | $searchForm = $('