Skip to content

Commit 54d4b5c

Browse files
author
liwentian
committed
fd
1 parent 9fb8b62 commit 54d4b5c

File tree

6 files changed

+117
-26
lines changed

6 files changed

+117
-26
lines changed

ebook/Backtracking.aux

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,33 @@
1515
\@writefile{toc}{\contentsline {subsubsection}{Description}{3}{section*.5}}
1616
\@writefile{lof}{\contentsline {figure}{\numberline {图\nobreakspace 1-1}{ \ignorespaces Phone Keyboard}}{3}{section*.5}}
1717
\newlabel{fig:phone-keyboard}{{1-1}{3}{Description}{section*.5}{}}
18-
\@writefile{toc}{\contentsline {subsubsection}{Solution}{3}{section*.6}}
18+
\@writefile{toc}{\contentsline {subsubsection}{Solution I}{3}{section*.6}}
19+
\@writefile{toc}{\contentsline {subsubsection}{Solution II}{4}{section*.7}}
1920
\@writefile{toc}{\contentsline {section}{\numberline {1.4}Generate Parentheses}{5}{section.1.4}}
20-
\@writefile{toc}{\contentsline {subsubsection}{Description}{5}{section*.7}}
21-
\@writefile{toc}{\contentsline {subsubsection}{Solution}{5}{section*.8}}
21+
\@writefile{toc}{\contentsline {subsubsection}{Description}{5}{section*.8}}
22+
\@writefile{toc}{\contentsline {subsubsection}{Solution}{5}{section*.9}}
2223
\@writefile{toc}{\contentsline {section}{\numberline {1.5}Permutations}{6}{section.1.5}}
23-
\@writefile{toc}{\contentsline {subsubsection}{Description}{6}{section*.9}}
24-
\@writefile{toc}{\contentsline {subsubsection}{Solution}{6}{section*.10}}
24+
\@writefile{toc}{\contentsline {subsubsection}{Description}{6}{section*.10}}
25+
\@writefile{toc}{\contentsline {subsubsection}{Solution}{6}{section*.11}}
2526
\@writefile{toc}{\contentsline {section}{\numberline {1.6}Word Search}{7}{section.1.6}}
26-
\@writefile{toc}{\contentsline {subsubsection}{Description}{7}{section*.11}}
27-
\@writefile{toc}{\contentsline {subsubsection}{Solution}{7}{section*.12}}
27+
\@writefile{toc}{\contentsline {subsubsection}{Description}{7}{section*.12}}
28+
\@writefile{toc}{\contentsline {subsubsection}{Solution}{7}{section*.13}}
2829
\@writefile{toc}{\contentsline {section}{\numberline {1.7}Word Search II}{8}{section.1.7}}
29-
\@writefile{toc}{\contentsline {subsubsection}{Description}{8}{section*.13}}
30-
\@writefile{toc}{\contentsline {subsubsection}{Solution}{8}{section*.14}}
30+
\@writefile{toc}{\contentsline {subsubsection}{Description}{8}{section*.14}}
31+
\@writefile{toc}{\contentsline {subsubsection}{Solution}{8}{section*.15}}
3132
\@writefile{toc}{\contentsline {section}{\numberline {1.8}Word Break}{10}{section.1.8}}
32-
\@writefile{toc}{\contentsline {subsubsection}{Description}{10}{section*.15}}
33-
\@writefile{toc}{\contentsline {subsubsection}{Solution}{10}{section*.16}}
33+
\@writefile{toc}{\contentsline {subsubsection}{Description}{10}{section*.16}}
34+
\@writefile{toc}{\contentsline {subsubsection}{Solution}{10}{section*.17}}
3435
\@writefile{toc}{\contentsline {section}{\numberline {1.9}Word Break II}{11}{section.1.9}}
35-
\@writefile{toc}{\contentsline {subsubsection}{Description}{11}{section*.17}}
36-
\@writefile{toc}{\contentsline {subsubsection}{Solution}{11}{section*.18}}
36+
\@writefile{toc}{\contentsline {subsubsection}{Description}{11}{section*.18}}
37+
\@writefile{toc}{\contentsline {subsubsection}{Solution}{11}{section*.19}}
38+
\@writefile{toc}{\contentsline {section}{\numberline {1.10}Combination Sum}{12}{section.1.10}}
39+
\@writefile{toc}{\contentsline {subsubsection}{Description}{12}{section*.20}}
40+
\@writefile{toc}{\contentsline {subsubsection}{Solution I}{12}{section*.21}}
41+
\@writefile{toc}{\contentsline {subsubsection}{Solution II}{13}{section*.22}}
3742
\FN@pp@footnotehinttrue
3843
\@setckpt{Backtracking}{
39-
\setcounter{page}{12}
44+
\setcounter{page}{14}
4045
\setcounter{equation}{0}
4146
\setcounter{enumi}{0}
4247
\setcounter{enumii}{0}
@@ -46,20 +51,20 @@
4651
\setcounter{mpfootnote}{0}
4752
\setcounter{part}{0}
4853
\setcounter{chapter}{1}
49-
\setcounter{section}{9}
54+
\setcounter{section}{10}
5055
\setcounter{subsection}{0}
5156
\setcounter{subsubsection}{0}
5257
\setcounter{paragraph}{0}
5358
\setcounter{subparagraph}{0}
5459
\setcounter{figure}{1}
5560
\setcounter{table}{0}
56-
\setcounter{FancyVerbLine}{25}
61+
\setcounter{FancyVerbLine}{21}
5762
\setcounter{pp@next@reset}{1}
5863
\setcounter{@fnserial}{0}
5964
\setcounter{Item}{0}
6065
\setcounter{Hfootnote}{0}
6166
\setcounter{Hy@AnnotLevel}{0}
62-
\setcounter{bookmark@seq@number}{10}
67+
\setcounter{bookmark@seq@number}{11}
6368
\setcounter{parentequation}{0}
6469
\setcounter{section@level}{3}
6570
}

ebook/Backtracking.tex

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ \subsubsection{Description}
110110

111111
\textbf{Output:} \code{["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]}.
112112

113-
\subsubsection{Solution}
113+
\subsubsection{Solution I}
114114

115115
\begin{Code}
116116
private final String[] ARR = {
@@ -135,8 +135,13 @@ \subsubsection{Solution}
135135
helper(digits, start + 1, list, s + c);
136136
}
137137
}
138+
\end{Code}
138139

139-
public List<String> letterCombinations2(String digits) {
140+
\subsubsection{Solution II}
141+
142+
\begin{Code}
143+
144+
public List<String> letterCombinations(String digits) {
140145
LinkedList<String> queue = new LinkedList<String>();
141146
if (digits.length() == 0) {
142147
return queue;
@@ -484,3 +489,83 @@ \subsubsection{Solution}
484489
return result;
485490
}
486491
\end{Code}
492+
493+
\newpage
494+
495+
\section{Combination Sum}
496+
\subsubsection{Description}
497+
Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.
498+
499+
The same repeated number may be chosen from C unlimited number of times.
500+
501+
Note:
502+
503+
All numbers (including target) will be positive integers.
504+
505+
The solution set must not contain duplicate combinations.
506+
507+
For example, given candidate set \code{[2, 3, 6, 7]} and target 7,
508+
509+
A solution set is:
510+
\begin{code}
511+
[
512+
[7],
513+
[2, 2, 3]
514+
]
515+
\end{code}
516+
517+
\subsubsection{Solution I}
518+
519+
\begin{Code}
520+
public List<List<Integer>> combinationSum(int[] candidates, int target) {
521+
List<List<Integer>> result = new LinkedList<>();
522+
helper(candidates, result, new LinkedList<>(), target, 0);
523+
return result;
524+
}
525+
526+
private void helper(int[] candidates, List<List<Integer>> result, List<Integer> list, int target, int index) {
527+
if (target < 0) {
528+
return;
529+
} else if (target == 0) {
530+
result.add(new LinkedList<>(list));
531+
return;
532+
} else if (index >= candidates.length) {
533+
return;
534+
}
535+
536+
list.add(candidates[index]);
537+
helper(candidates, result, list, target - candidates[index], index);
538+
list.remove(list.size() - 1);
539+
540+
helper(candidates, result, list, target, index + 1);
541+
}
542+
543+
\end{Code}
544+
545+
\newpage
546+
547+
\subsubsection{Solution II}
548+
549+
\begin{Code}
550+
551+
public List<List<Integer>> combinationSum(int[] candidates, int target) {
552+
List<List<Integer>> result = new LinkedList<>();
553+
dfs(candidates, target, 0, result, new LinkedList<Integer>());
554+
return result;
555+
}
556+
557+
private void dfs(int[] candidates, int target, int start, List<List<Integer>> result, List<Integer> list) {
558+
if (target < 0) {
559+
return;
560+
}
561+
if (target == 0) {
562+
result.add(new LinkedList<>(list));
563+
return;
564+
}
565+
for (int i = start; i < candidates.length; i++) {
566+
list.add(candidates[i]);
567+
dfs(candidates, target - candidates[i], i, result, list);
568+
list.remove(list.size() - 1);
569+
}
570+
}
571+
\end{Code}

ebook/leetcode.log

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This is XeTeX, Version 3.14159265-2.6-0.99996 (TeX Live 2016) (preloaded format=xelatex 2017.9.4) 5 SEP 2017 16:09
1+
This is XeTeX, Version 3.14159265-2.6-0.99996 (TeX Live 2016) (preloaded format=xelatex 2017.9.4) 5 SEP 2017 16:17
22
entering extended mode
33
restricted \write18 enabled.
44
%&-line parsing enabled.
@@ -1906,7 +1906,7 @@ File: images/phone.png Graphic file (type QTm)
19061906
. with NFSS spec.: <->"Latin Modern Mono/BI/OT:script=latn;language=DFLT;"
19071907
. - 'bold italic small caps' (bx/itsc) with NFSS spec.:
19081908
.................................................
1909-
[3] [4] [5] [6] [7] [8] [9] [10]) [11]
1909+
[3] [4] [5] [6] [7] [8] [9] [10] [11] [12]) [13]
19101910
No file leetcode.ind.
19111911
Package atveryend Info: Empty hook `BeforeClearDocument' on input line 42.
19121912
Package atveryend Info: Empty hook `AfterLastShipout' on input line 42.
@@ -1916,12 +1916,12 @@ Package atveryend Info: Empty hook `AtEndAfterFileList' on input line 42.
19161916
Package atveryend Info: Empty hook `AtVeryVeryEnd' on input line 42.
19171917
)
19181918
Here is how much of TeX's memory you used:
1919-
29160 strings out of 493591
1920-
551638 string characters out of 6143547
1921-
569017 words of memory out of 5000000
1922-
32193 multiletter control sequences out of 15000+600000
1919+
29161 strings out of 493591
1920+
551645 string characters out of 6143547
1921+
569215 words of memory out of 5000000
1922+
32194 multiletter control sequences out of 15000+600000
19231923
5076 words of font info for 53 fonts, out of 8000000 for 9000
19241924
1347 hyphenation exceptions out of 8191
19251925
65i,11n,77p,10414b,588s stack positions out of 5000i,500n,10000p,200000b,80000s
19261926

1927-
Output written on leetcode.pdf (11 pages).
1927+
Output written on leetcode.pdf (13 pages).

ebook/leetcode.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
\BOOKMARK [1][-]{section.1.7}{\376\377\0001\000.\0007\000\040\000W\000o\000r\000d\000\040\000S\000e\000a\000r\000c\000h\000\040\000I\000I}{chapter.1}% 8
99
\BOOKMARK [1][-]{section.1.8}{\376\377\0001\000.\0008\000\040\000W\000o\000r\000d\000\040\000B\000r\000e\000a\000k}{chapter.1}% 9
1010
\BOOKMARK [1][-]{section.1.9}{\376\377\0001\000.\0009\000\040\000W\000o\000r\000d\000\040\000B\000r\000e\000a\000k\000\040\000I\000I}{chapter.1}% 10
11+
\BOOKMARK [1][-]{section.1.10}{\376\377\0001\000.\0001\0000\000\040\000C\000o\000m\000b\000i\000n\000a\000t\000i\000o\000n\000\040\000S\000u\000m}{chapter.1}% 11

ebook/leetcode.pdf

2.89 KB
Binary file not shown.

ebook/leetcode.synctex.gz

4.16 KB
Binary file not shown.

0 commit comments

Comments
 (0)