Skip to content

Commit 96735af

Browse files
author
liwentian
committed
fd
1 parent 6009705 commit 96735af

15 files changed

+2364
-0
lines changed

ebook/.DS_Store

0 Bytes
Binary file not shown.

ebook/tree/.DS_Store

8 KB
Binary file not shown.

ebook/tree/Tree.aux

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
\relax
2+
\providecommand\hyper@newdestlabel[2]{}
3+
\FN@pp@footnotehinttrue
4+
\@writefile{toc}{\contentsline {chapter}{\numberline {第1章\hspace {0.3em}}Tree}{1}{chapter.1}}
5+
\@writefile{lof}{\addvspace {10\p@ }}
6+
\@writefile{lot}{\addvspace {10\p@ }}
7+
\@writefile{toc}{\contentsline {section}{\numberline {1.1}Maximum Depth of Binary Tree}{1}{section.1.1}}
8+
\@writefile{toc}{\contentsline {subsubsection}{Description}{1}{section*.2}}
9+
\@writefile{toc}{\contentsline {subsubsection}{Solution}{1}{section*.3}}
10+
\@writefile{toc}{\contentsline {section}{\numberline {1.2}Invert Binary Tree}{2}{section.1.2}}
11+
\@writefile{toc}{\contentsline {subsubsection}{Description}{2}{section*.4}}
12+
\@writefile{toc}{\contentsline {subsubsection}{Solution I}{2}{section*.5}}
13+
\@writefile{toc}{\contentsline {subsubsection}{Solution II}{2}{section*.6}}
14+
\FN@pp@footnotehinttrue
15+
\@setckpt{Tree}{
16+
\setcounter{page}{3}
17+
\setcounter{equation}{0}
18+
\setcounter{enumi}{0}
19+
\setcounter{enumii}{0}
20+
\setcounter{enumiii}{0}
21+
\setcounter{enumiv}{0}
22+
\setcounter{footnote}{0}
23+
\setcounter{mpfootnote}{0}
24+
\setcounter{part}{0}
25+
\setcounter{chapter}{1}
26+
\setcounter{section}{2}
27+
\setcounter{subsection}{0}
28+
\setcounter{subsubsection}{0}
29+
\setcounter{paragraph}{0}
30+
\setcounter{subparagraph}{0}
31+
\setcounter{figure}{0}
32+
\setcounter{table}{0}
33+
\setcounter{FancyVerbLine}{26}
34+
\setcounter{pp@next@reset}{1}
35+
\setcounter{@fnserial}{0}
36+
\setcounter{Item}{0}
37+
\setcounter{Hfootnote}{0}
38+
\setcounter{Hy@AnnotLevel}{0}
39+
\setcounter{bookmark@seq@number}{3}
40+
\setcounter{parentequation}{0}
41+
\setcounter{section@level}{3}
42+
}

ebook/tree/Tree.tex

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
\chapter{Tree}
2+
3+
\section{Maximum Depth of Binary Tree} %%%%%%%%%%%%%%%%%%%%%%
4+
5+
\subsubsection{Description}
6+
7+
Given a binary tree, find its maximum depth.
8+
9+
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
10+
11+
\subsubsection{Solution}
12+
13+
\begin{Code}
14+
private int maxDepth(TreeNode node) {
15+
if (node == null) {
16+
return 0;
17+
}
18+
return Math.max(maxDepth(node.left), maxDepth(node.right)) + 1;
19+
}
20+
\end{Code}
21+
22+
\newpage
23+
24+
\section{Invert Binary Tree} %%%%%%%%%%%%%%%%%%%%%%
25+
26+
\subsubsection{Description}
27+
28+
Invert a binary tree.
29+
\begin{Code}
30+
4 4
31+
/ \ / \
32+
2 7 to 7 2
33+
/ \ / \ / \ / \
34+
1 3 6 9 9 6 3 1
35+
\end{Code}
36+
37+
\subsubsection{Solution I}
38+
39+
\begin{Code}
40+
public TreeNode invertTree(TreeNode root) {
41+
if (root == null) {
42+
return null;
43+
}
44+
45+
TreeNode right = root.right;
46+
root.right = invertTree(root.left);
47+
root.left = invertTree(right);
48+
return root;
49+
}
50+
\end{Code}
51+
52+
\subsubsection{Solution II}
53+
54+
\begin{Code}
55+
public TreeNode invertTree(TreeNode root) {
56+
if (root == null) {
57+
return null;
58+
}
59+
60+
Queue<TreeNode> queue = new LinkedList<TreeNode>();
61+
queue.offer(root);
62+
63+
while (!queue.isEmpty()) {
64+
TreeNode node = queue.poll();
65+
66+
TreeNode left = node.left;
67+
node.left = node.right;
68+
node.right = left;
69+
70+
if (node.left != null) {
71+
queue.offer(node.left);
72+
}
73+
74+
if (node.right != null) {
75+
queue.offer(node.right);
76+
}
77+
}
78+
79+
return root;
80+
}
81+
\end{Code}

ebook/tree/format.cls

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
\usepackage[centering,paperwidth=180mm,paperheight=230mm,%
2+
body={480pt,580pt},marginparsep=10pt,marginpar=50pt]{geometry}
3+
\usepackage{color}
4+
\usepackage{enumitem}
5+
\usepackage{fancyvrb}
6+
\usepackage[bottom,perpage,symbol*]{footmisc}
7+
\usepackage{graphicx}
8+
\usepackage[hidelinks]{hyperref}
9+
\usepackage{makeidx}
10+
\usepackage[toc]{multitoc}
11+
\usepackage{pifont}
12+
\usepackage{underscore}
13+
\usepackage{amsmath}
14+
15+
\DefineFNsymbols*{chinese}{{\ding{172}}{\ding{173}}{\ding{174}}{\ding{175}}%
16+
{\ding{176}}{\ding{177}}{\ding{178}}{\ding{179}}{\ding{180}}{\ding{181}}}
17+
\setfnsymbol{chinese}
18+
19+
\hypersetup{bookmarksnumbered=true,bookmarksdepth=2}
20+
21+
\CTEXsetup[number={\thechapter}]{chapter}
22+
\CTEXsetup[format+={\raggedleft}]{chapter}
23+
\CTEXsetup[beforeskip={10pt}]{chapter}
24+
\CTEXsetup[afterskip={30pt}]{chapter}
25+
\def\CTEX@chapter@aftername{\par} % \CTEXsetup[aftername={\par}]{chapter}
26+
\CTEXsetup[format+={\raggedright}]{section}
27+
\CTEXsetup[beforeskip={-3.0ex plus -1ex minus -.2ex}]{section}
28+
\CTEXsetup[afterskip={2.3ex plus .2ex minus 0.2ex}]{section}
29+
30+
\renewcommand \thefigure{\thechapter-\arabic{figure}}
31+
\renewcommand \thetable{\thechapter-\arabic{table}}
32+
33+
\newcommand\figcaption[1]{\def\@captype{figure}\caption{#1}}
34+
\newcommand\tabcaption[1]{\def\@captype{table}\caption{#1}}
35+
36+
\long\def\@caption#1[#2]#3{%
37+
\addcontentsline{\csname ext@#1\endcsname}{#1}%
38+
{\protect\numberline{\csname fnum@#1\endcsname}{ \ignorespaces #2}}% change "the" to "fnum@"
39+
\normalsize
40+
\@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}}
41+
42+
\long\def\@makecaption#1#2{%
43+
\vskip\abovecaptionskip
44+
\sbox\@tempboxa{#1\quad#2}%
45+
\ifdim \wd\@tempboxa >\hsize
46+
#1\quad#2\par
47+
\else
48+
\global \@minipagefalse
49+
\hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
50+
\fi
51+
\vskip\belowcaptionskip}
52+
53+
\setlength\abovecaptionskip{0pt}
54+
55+
\setmainfont{Times New Roman}
56+
%\setmainfont{Linux Libertine}
57+
%\setmainfont{TeX Gyre Pagella}
58+
\newfontfamily\urlfont{PT Sans Narrow}
59+
%\setmonofont[AutoFakeBold=1.6,AutoFakeSlant=0.17,Mapping=tex-text-tt]{Inconsolata}
60+
\setCJKfamilyfont{zhyou}{YouYuan}
61+
62+
\newcommand{\fn}[1]{\texttt{#1}}
63+
\newcommand{\sfn}[1]{\texttt{\small #1}}
64+
\newcommand{\kw}[1]{\textsf{#1}}
65+
\newcommand{\myurl}[1]{{\urlfont #1}}
66+
\newcommand{\mpar}[1]{\marginpar[\hfill\kaishu #1]{\kaishu #1}}
67+
\newcommand{\mn}[1]{\texttt{\bs #1}}
68+
\renewcommand{\today}{\the\year-\the\month-\the\day}
69+
\newcommand\bs{\textbackslash}
70+
\newcommand{\code}[1]{\small{\fontspec{Latin Modern Mono} #1}}
71+
72+
\newcommand\begindot{\begin{itemize}
73+
[itemsep=2pt plus 2pt minus 2pt,%
74+
topsep=3pt plus 2pt minus 2pt,%
75+
parsep=0pt plus 2pt minus 2pt]}
76+
\newcommand\myenddot{\end{itemize}}
77+
78+
\newcommand\beginnum{\begin{enumerate}
79+
[itemsep=2pt plus 2pt minus 2pt,%
80+
topsep=3pt plus 2pt minus 2pt,%
81+
parsep=0pt plus 2pt minus 2pt]}
82+
\newcommand\myendnum{\end{enumerate}}
83+
84+
\DefineVerbatimEnvironment%
85+
{Code}{Verbatim}
86+
{fontsize=\small,baselinestretch=0.9,xleftmargin=3mm}
87+
88+
\raggedbottom
89+
%\setlength{\parskip}{1ex plus .5ex minus .5ex}
90+
91+
\input{verbatim.cls}
92+
\DefineVerbatimEnvironment%
93+
{Codex}{Verbatim}
94+
{fontsize=\small,baselinestretch=0.9,xleftmargin=3mm,%
95+
frame=lines,labelposition=all,framesep=5pt}
96+
97+
\DefineVerbatimEnvironment%
98+
{Code}{Verbatim}
99+
{fontsize=\small,baselinestretch=0.9,xleftmargin=3mm}
100+
101+
\makeindex

ebook/tree/leetcode-tree.aux

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
\relax
2+
\providecommand\hyper@newdestlabel[2]{}
3+
\providecommand\HyperFirstAtBeginDocument{\AtBeginDocument}
4+
\HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined
5+
\global\let\oldcontentsline\contentsline
6+
\gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}}
7+
\global\let\oldnewlabel\newlabel
8+
\gdef\newlabel#1#2{\newlabelxx{#1}#2}
9+
\gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}}
10+
\AtEndDocument{\ifx\hyper@anchor\@undefined
11+
\let\contentsline\oldcontentsline
12+
\let\newlabel\oldnewlabel
13+
\fi}
14+
\fi}
15+
\global\let\hyper@last\relax
16+
\gdef\HyperFirstAtBeginDocument#1{#1}
17+
\providecommand*\HyPL@Entry[1]{}
18+
\catcode 95\active
19+
\@input{title.aux}
20+
\HyPL@Entry{0<</S/r>>}
21+
\providecommand {\FN@pp@footnotehinttrue }{}
22+
\providecommand {\FN@pp@footnote@aux }[2]{}
23+
\FN@pp@footnotehinttrue
24+
\FN@pp@footnotehinttrue
25+
\FN@pp@footnotehinttrue
26+
\FN@pp@footnotehinttrue
27+
\@input{Tree.aux}
28+
\HyPL@Entry{2<</S/D>>}
29+
\FN@pp@footnotehinttrue

ebook/tree/leetcode-tree.idx

Whitespace-only changes.

0 commit comments

Comments
 (0)