forked from soulmachine/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4534ed2
Showing
12 changed files
with
421 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#C++版 | ||
----------------- | ||
**下载**:<a href="https://github.com/soulmachine/acm-cheat-sheet/blob/master/C++/%E6%89%8B%E5%86%99%E4%BB%A3%E7%A0%81%E5%BF%85%E5%A4%87%E6%89%8B%E5%86%8C(C++%E7%89%88).pdf?raw=true">手写代码必备手册(C++版).pdf</a> | ||
|
||
书的内容与Java版一摸一样,不过代码是用C++写的。本书的代码使用 C++ 11 标准。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
\subsubsection{内容简介} | ||
本书的目标读者是准备去北美找工作的码农,也适用于在国内找工作的码农,以及刚接触ACM算法竞赛的新手。 | ||
|
||
本书包含了 LeetCode Online Judge(\myurl{http://leetcode.com/onlinejudge})所有题目的答案, | ||
所有代码经过精心编写,编码规范良好,适合读者反复揣摩,模仿,甚至在纸上默写。 | ||
|
||
全书的代码,使用C++ 11的编写,并在 LeetCode Online Judge 上测试通过。本书中的代码规范,跟在公司中的工程规范略有不同,为了使代码短(方便迅速实现): | ||
|
||
\begindot | ||
\item 所有代码都是单一文件。这是因为一般OJ网站,提交代码的时候只有一个文本框,如果还是 | ||
按照标准做法,比如分为头文件.h和源代码.cpp,无法在网站上提交; | ||
|
||
\item 大量使用 STL,让代码更短,shorter is better; | ||
|
||
\item 不提倡防御式编程。不需要检查malloc()/new 返回的指针是否为NULL;不需要检查内部函数入口 | ||
参数的有效性;使用纯C基于对象编程时,调用对象的成员方法,不需要检查对象自身是否为NULL。 | ||
\myenddot | ||
|
||
本手册假定读者已经学过《数据结构》\footnote{《数据结构》,严蔚敏等著,清华大学出版社, | ||
\myurl{http://book.douban.com/subject/2024655/}}, | ||
《算法》\footnote{《Algorithms》,Robert Sedgewick, Addison-Wesley Professional, \myurl{http://book.douban.com/subject/4854123/}} | ||
这两门课,熟练掌握C++或Java。 | ||
|
||
\subsubsection{GitCafe地址} | ||
本书是开源的,项目地址:\myurl{https://gitcafe.com/soulmachine/LeetCode} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
\chapter{编程技巧} | ||
把较大的数组放在main函数外,作为全局变量,这样可以防止栈溢出,因为栈的大小是有限制的。 | ||
|
||
如果能够预估栈,队列的上限,则不要用\fn{std::stack, std::queue},使用数组来模拟,这样速度最快。 | ||
|
||
输入数据一般放在全局变量,且在运行过程中不要修改这些变量。 | ||
|
||
在判断两个浮点数a和b是否相等时,不要用\fn{a==b},应该判断二者之差的绝对值\fn{fabs(a-b)}是否小于某个阀值,例如\fn{1e-9}。 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
\usepackage[centering,paperwidth=180mm,paperheight=230mm,% | ||
body={390pt,530pt},marginparsep=10pt,marginpar=50pt]{geometry} | ||
\usepackage{color} | ||
\usepackage{enumitem} | ||
\usepackage{fancyvrb} | ||
\usepackage[bottom,perpage,symbol*]{footmisc} | ||
\usepackage{graphicx} | ||
\usepackage[hidelinks]{hyperref} | ||
\usepackage{makeidx} | ||
\usepackage[toc]{multitoc} | ||
\usepackage{pifont} | ||
\usepackage{underscore} | ||
\usepackage{amsmath} | ||
|
||
\DefineFNsymbols*{chinese}{{\ding{172}}{\ding{173}}{\ding{174}}{\ding{175}}% | ||
{\ding{176}}{\ding{177}}{\ding{178}}{\ding{179}}{\ding{180}}{\ding{181}}} | ||
\setfnsymbol{chinese} | ||
|
||
\hypersetup{bookmarksnumbered=true,bookmarksdepth=2} | ||
|
||
\CTEXsetup[number={\thechapter}]{chapter} | ||
\CTEXsetup[format+={\raggedleft}]{chapter} | ||
\CTEXsetup[beforeskip={10pt}]{chapter} | ||
\CTEXsetup[afterskip={30pt}]{chapter} | ||
\def\CTEX@chapter@aftername{\par} % \CTEXsetup[aftername={\par}]{chapter} | ||
\CTEXsetup[format+={\raggedright}]{section} | ||
\CTEXsetup[beforeskip={-3.0ex plus -1ex minus -.2ex}]{section} | ||
\CTEXsetup[afterskip={2.3ex plus .2ex minus 0.2ex}]{section} | ||
|
||
\renewcommand \thefigure{\thechapter-\arabic{figure}} | ||
\renewcommand \thetable{\thechapter-\arabic{table}} | ||
|
||
\newcommand\figcaption[1]{\def\@captype{figure}\caption{#1}} | ||
\newcommand\tabcaption[1]{\def\@captype{table}\caption{#1}} | ||
|
||
\long\def\@caption#1[#2]#3{% | ||
\addcontentsline{\csname ext@#1\endcsname}{#1}% | ||
{\protect\numberline{\csname fnum@#1\endcsname}{ \ignorespaces #2}}% change "the" to "fnum@" | ||
\normalsize | ||
\@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}} | ||
|
||
\long\def\@makecaption#1#2{% | ||
\vskip\abovecaptionskip | ||
\sbox\@tempboxa{#1\quad#2}% | ||
\ifdim \wd\@tempboxa >\hsize | ||
#1\quad#2\par | ||
\else | ||
\global \@minipagefalse | ||
\hb@xt@\hsize{\hfil\box\@tempboxa\hfil}% | ||
\fi | ||
\vskip\belowcaptionskip} | ||
|
||
\setlength\abovecaptionskip{0pt} | ||
|
||
%\setmainfont{Times New Roman} | ||
\setmainfont{Linux Libertine O} | ||
%\setmainfont{TeX Gyre Pagella} | ||
\newfontfamily\urlfont{PT Sans Narrow} | ||
%\setmonofont[AutoFakeBold=1.6,AutoFakeSlant=0.17,Mapping=tex-text-tt]{Inconsolata} | ||
\setCJKfamilyfont{zhyou}{YouYuan} | ||
|
||
\newcommand{\fn}[1]{\texttt{#1}} | ||
\newcommand{\sfn}[1]{\texttt{\small #1}} | ||
\newcommand{\kw}[1]{\textsf{#1}} | ||
\newcommand{\myurl}[1]{{\urlfont #1}} | ||
\newcommand{\mpar}[1]{\marginpar[\hfill\kaishu #1]{\kaishu #1}} | ||
\newcommand{\mn}[1]{\texttt{\bs #1}} | ||
\renewcommand{\today}{\the\year-\the\month-\the\day} | ||
\newcommand\bs{\textbackslash} | ||
|
||
\newcommand\begindot{\begin{itemize} | ||
[itemsep=2pt plus 2pt minus 2pt,% | ||
topsep=3pt plus 2pt minus 2pt,% | ||
parsep=0pt plus 2pt minus 2pt]} | ||
\newcommand\myenddot{\end{itemize}} | ||
|
||
\newcommand\beginnum{\begin{enumerate} | ||
[itemsep=2pt plus 2pt minus 2pt,% | ||
topsep=3pt plus 2pt minus 2pt,% | ||
parsep=0pt plus 2pt minus 2pt]} | ||
\newcommand\myendnum{\end{enumerate}} | ||
|
||
\DefineVerbatimEnvironment% | ||
{Code}{Verbatim} | ||
{fontsize=\small,baselinestretch=0.9,xleftmargin=3mm} | ||
|
||
\raggedbottom | ||
%\setlength{\parskip}{1ex plus .5ex minus .5ex} | ||
|
||
\input{verbatim.cls} | ||
\DefineVerbatimEnvironment% | ||
{Codex}{Verbatim} | ||
{fontsize=\small,baselinestretch=0.9,xleftmargin=3mm,% | ||
frame=lines,labelposition=all,framesep=5pt} | ||
|
||
\DefineVerbatimEnvironment% | ||
{Code}{Verbatim} | ||
{fontsize=\small,baselinestretch=0.9,xleftmargin=3mm} | ||
|
||
\makeindex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
\documentclass[10pt,adobefonts,fancyhdr,hyperref,UTF8]{ctexbook} | ||
|
||
\usepackage{multirow} | ||
% for \soul 删除线 | ||
\usepackage{ulem} | ||
% 表头斜线 | ||
\usepackage{diagbox} | ||
|
||
\makeatletter | ||
\input{format.cls} | ||
\makeatother | ||
|
||
\begin{document} | ||
\sloppy | ||
\newcommand\BookTitle{LeetCode题解} | ||
\pagestyle{fancy} | ||
\fancyhf{} | ||
\fancyhead[RE]{\normalfont\small\rmfamily\nouppercase{\leftmark}} | ||
\fancyhead[LO]{\normalfont\small\rmfamily\nouppercase{\rightmark}} | ||
\fancyhead[LE,RO]{\thepage} | ||
%\fancyfoot[LE,LO]{\small\normalfont\youyuan\BookTitle} | ||
%\fancyfoot[RE,RO]{\textsf{\small \color{blue} https://gitcafe.com/soulmachine/LeetCode}} | ||
|
||
\makeatletter | ||
\@openrightfalse | ||
\makeatother | ||
|
||
\frontmatter % 开始前言目录,页码用罗马数字 | ||
|
||
\include{title} | ||
|
||
\tableofcontents | ||
|
||
\mainmatter % 开始正文,页码用阿拉伯数字 | ||
|
||
\graphicspath{{diagrams/}} | ||
|
||
\include{chapProgrammingTrick} | ||
|
||
\appendix % 开始附录,章用字母编号 | ||
\printindex | ||
|
||
\end{document} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
; TECkit mapping for TeX input conventions <-> Unicode characters | ||
|
||
LHSName "TeX-text" | ||
RHSName "UNICODE" | ||
|
||
pass(Unicode) | ||
|
||
; ligatures from Knuth's original CMR fonts | ||
;U+002D U+002D <> U+2013 ; -- -> en dash | ||
;U+002D U+002D U+002D <> U+2014 ; --- -> em dash | ||
|
||
;U+0027 <> U+2019 ; ' -> right single quote | ||
;U+0027 U+0027 <> U+201D ; '' -> right double quote | ||
;U+0022 > U+201D ; " -> right double quote | ||
|
||
;U+0060 <> U+2018 ; ` -> left single quote | ||
;U+0060 U+0060 <> U+201C ; `` -> left double quote | ||
|
||
;U+0021 U+0060 <> U+00A1 ; !` -> inverted exclam | ||
;U+003F U+0060 <> U+00BF ; ?` -> inverted question | ||
|
||
; additions supported in T1 encoding | ||
;U+002C U+002C <> U+201E ; ,, -> DOUBLE LOW-9 QUOTATION MARK | ||
;U+003C U+003C <> U+00AB ; << -> LEFT POINTING GUILLEMET | ||
;U+003E U+003E <> U+00BB ; >> -> RIGHT POINTING GUILLEMET | ||
|
||
;U+0027 <> U+2019 ; ' -> right single quote | ||
;U+0022 > U+201D ; " -> right double quote |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
\relax | ||
\providecommand\hyper@newdestlabel[2]{} | ||
\@writefile{toc}{\contentsline {subsubsection}{内容简介}{i}{section*.1}} | ||
\FN@pp@footnote@aux{1}{i} | ||
\FN@pp@footnote@aux{2}{i} | ||
\@writefile{toc}{\contentsline {subsubsection}{GitCafe地址}{i}{section*.2}} | ||
\FN@pp@footnotehinttrue | ||
\@setckpt{title}{ | ||
\setcounter{page}{2} | ||
\setcounter{equation}{0} | ||
\setcounter{enumi}{0} | ||
\setcounter{enumii}{0} | ||
\setcounter{enumiii}{0} | ||
\setcounter{enumiv}{0} | ||
\setcounter{footnote}{0} | ||
\setcounter{mpfootnote}{0} | ||
\setcounter{CTEX@sectiondepth}{2} | ||
\setcounter{part}{0} | ||
\setcounter{chapter}{0} | ||
\setcounter{section}{0} | ||
\setcounter{subsection}{0} | ||
\setcounter{subsubsection}{0} | ||
\setcounter{paragraph}{0} | ||
\setcounter{subparagraph}{0} | ||
\setcounter{figure}{0} | ||
\setcounter{table}{0} | ||
\setcounter{FancyVerbLine}{0} | ||
\setcounter{pp@next@reset}{3} | ||
\setcounter{@fnserial}{2} | ||
\setcounter{Item}{0} | ||
\setcounter{Hfootnote}{2} | ||
\setcounter{Hy@AnnotLevel}{0} | ||
\setcounter{bookmark@seq@number}{0} | ||
\setcounter{parentequation}{0} | ||
\setcounter{section@level}{3} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
\thispagestyle{plain} | ||
\begin{center} | ||
{\LARGE\textbf{\BookTitle}} | ||
|
||
\vspace{1em} | ||
{\large 戴方勤 ([email protected])} | ||
|
||
\vspace{1ex} | ||
\myurl{https://gitcafe.com/soulmachine/LeetCode} | ||
|
||
\vspace{1ex} | ||
最后更新 \today | ||
|
||
\vspace{1em} | ||
\textbf{\large 版权声明} | ||
\end{center} | ||
\noindent 本作品采用“Creative Commons 署名-非商业性使用-相同方式共享 3.0 Unported许可协议 | ||
(cc by-nc-sa)”进行许可。 | ||
\texttt{\small http://creativecommons.org/licenses/by-nc-sa/3.0/} | ||
|
||
\vspace{1em} | ||
\input{abstract} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
\def\FV@SetLineWidth{% | ||
\if@FV@ResetMargins\else | ||
\advance\leftmargin\@totalleftmargin | ||
\fi | ||
\advance\leftmargin\FV@XLeftMargin\relax | ||
\advance\rightmargin\FV@XRightMargin\relax | ||
\linewidth\hsize | ||
%\advance\linewidth-\leftmargin | ||
%\advance\linewidth-\rightmargin | ||
\hfuzz\FancyVerbHFuzz\relax} | ||
|
||
|
||
\def\FV@SingleFrameLine#1{% | ||
%% DG/SR modification end | ||
\hbox to\z@{% | ||
%\kern\leftmargin | ||
%% DG/SR modification begin - Jun. 22, 1998 | ||
\ifnum#1=\z@ | ||
\let\FV@Label\FV@LabelBegin | ||
\else | ||
\let\FV@Label\FV@LabelEnd | ||
\fi | ||
\ifx\FV@Label\relax | ||
%% DG/SR modification end | ||
\FancyVerbRuleColor{\vrule \@width\linewidth \@height\FV@FrameRule}% | ||
%% DG/SR modification begin - Jun. 22, 1998 | ||
\else | ||
\ifnum#1=\z@ | ||
\setbox\z@\hbox{\strut\enspace\urlfont\FV@LabelBegin\strut}% | ||
\else | ||
\setbox\z@\hbox{\strut\enspace\urlfont\FV@LabelEnd\strut}% | ||
\fi | ||
\@tempdimb=\dp\z@ | ||
\advance\@tempdimb -.5\ht\z@ | ||
\@tempdimc=\linewidth | ||
\advance\@tempdimc -\wd\z@ | ||
%\divide\@tempdimc\tw@ | ||
\ifnum#1=\z@ % Top line | ||
\ifx\FV@LabelPositionTopLine\relax | ||
\FancyVerbRuleColor{\vrule \@width\linewidth \@height\FV@FrameRule}% | ||
\else | ||
\FV@FrameLineWithLabel | ||
\fi | ||
\else % Bottom line | ||
\ifx\FV@LabelPositionBottomLine\relax | ||
\FancyVerbRuleColor{\vrule \@width\linewidth \@height\FV@FrameRule}% | ||
\else | ||
\FV@FrameLineWithLabel | ||
\fi | ||
\fi | ||
\fi | ||
%% DG/SR modification end | ||
\hss}} | ||
|
||
|
||
%% DG/SR modification begin - May. 19, 1998 | ||
\def\FV@FrameLineWithLabel{% | ||
\ht\z@\@tempdimb\dp\z@\@tempdimb% | ||
\FancyVerbRuleColor{% | ||
\raise 0.5ex\hbox{\vrule \@width\@tempdimc \@height\FV@FrameRule}% | ||
\raise\@tempdimb\box\z@}} | ||
%% DG/SR modification end | ||
|
||
|
||
\def\FV@EndListFrame@Lines{% | ||
\begingroup | ||
%\vskip 0.5ex | ||
\baselineskip\z@skip | ||
\kern\FV@FrameSep\relax | ||
%% DG/SR modification begin - May. 19, 1998 | ||
%% \FV@SingleFrameLine | ||
\FV@SingleFrameLine{\@ne}% | ||
%% DG/SR modification end | ||
\endgroup} | ||
|
||
\newskip\mytopsep | ||
\setlength{\mytopsep}{4pt plus 2pt minus 3pt} | ||
|
||
\def\FV@ListVSpace{% | ||
\@topsepadd\mytopsep | ||
\if@noparlist\advance\@topsepadd\partopsep\fi | ||
\if@inlabel | ||
\vskip\parskip | ||
\else | ||
\if@nobreak | ||
\vskip\parskip | ||
\clubpenalty\@M | ||
\else | ||
\addpenalty\@beginparpenalty | ||
\@topsep\@topsepadd | ||
\advance\@topsep\parskip | ||
\addvspace\@topsep | ||
\fi | ||
\fi | ||
%\showthe \@topsepadd | ||
%\showthe \topsep | ||
%\showthe \partopsep | ||
%\showthe \parskip | ||
\global\@nobreakfalse | ||
\global\@inlabelfalse | ||
\global\@minipagefalse | ||
\global\@newlistfalse} | ||
|
||
\def\FV@EndList{% | ||
\FV@ListProcessLastLine | ||
\FV@EndListFrame | ||
%\showthe \@topsepadd | ||
\@endparenv | ||
\endgroup | ||
\@endpetrue} | ||
|
||
\def\theFancyVerbLine{\sffamily\scriptsize\arabic{FancyVerbLine}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#Java版 | ||
----------------- | ||
书的内容与C++版一摸一样,不过代码是用Java写的。本书的代码要求 Java 6 以上。 |
Oops, something went wrong.